1
This commit is contained in:
parent
461f66af6a
commit
8d8e92d31e
@ -1,13 +1,11 @@
|
||||
package f5
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"math/rand"
|
||||
"q5"
|
||||
"reflect"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
type MetaTable interface {
|
||||
@ -119,8 +117,7 @@ func (this *RawMetaTable[T]) Load() {
|
||||
if this.NoLoad {
|
||||
return
|
||||
}
|
||||
if f, err := os.Open(this.FileName); err == nil {
|
||||
jsonStr, _ := bufio.NewReader(f).ReadString(0)
|
||||
if jsonStr, err := ReadJsonFile(this.FileName); err == nil {
|
||||
switch q5.JsonStrType(jsonStr) {
|
||||
case q5.JSON_ARRAY:
|
||||
break
|
||||
|
8
sysutils_unix.go
Normal file
8
sysutils_unix.go
Normal file
@ -0,0 +1,8 @@
|
||||
//go:build unix
|
||||
// +build unix
|
||||
|
||||
package f5
|
||||
|
||||
func ReadJsonFile(fileName string) (string, error) {
|
||||
return q5.ReadTextFile(fileName)
|
||||
}
|
29
sysutils_windows.go
Normal file
29
sysutils_windows.go
Normal file
@ -0,0 +1,29 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package f5
|
||||
|
||||
import (
|
||||
"q5"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ReadJsonFile(fileName string) (string, error) {
|
||||
if tmpStr, err := q5.ReadTextFile(fileName); err != nil {
|
||||
return tmpStr, err
|
||||
} else {
|
||||
switch q5.JsonStrType(tmpStr) {
|
||||
case q5.JSON_ARRAY, q5.JSON_OBJECT:
|
||||
{
|
||||
return tmpStr, nil
|
||||
}
|
||||
default:
|
||||
index := strings.LastIndex(fileName, "/")
|
||||
if index <= 0 {
|
||||
return q5.ReadTextFile(fileName + "/" + tmpStr)
|
||||
} else {
|
||||
return q5.ReadTextFile(fileName[0:index+1] + tmpStr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user