1 parent
096b4b8fed
commit
cc4aa851bc
43 files changed
+256
-396
No files matched your search
@@ -1,11 +1,8 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"io/fs"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var IsInit bool
|
||||
@@ -38,9 +35,6 @@ type Config struct {
|
||||
TablesInitData map[string]string `json:"-"`
|
||||
}
|
||||
|
||||
//go:embed tables/*
|
||||
var tableConfig embed.FS
|
||||
|
||||
const DBTypeMySQL = "mysql"
|
||||
const DBTypeSQLite = "sqlite"
|
||||
const SSLTypeAuto = "0" //自动生成证书
|
||||
@@ -76,38 +70,6 @@ func Init() {
|
||||
Instance.Domains = []string{Instance.Domain}
|
||||
}
|
||||
|
||||
// 读取表设置
|
||||
Instance.Tables = map[string]string{}
|
||||
Instance.TablesInitData = map[string]string{}
|
||||
|
||||
root := "tables/mysql"
|
||||
if Instance.DbType == DBTypeSQLite {
|
||||
root = "tables/sqlite"
|
||||
}
|
||||
err = fs.WalkDir(tableConfig, root, func(path string, info fs.DirEntry, err error) error {
|
||||
if !info.IsDir() && strings.HasSuffix(info.Name(), ".sql") {
|
||||
tableName := strings.ReplaceAll(info.Name(), ".sql", "")
|
||||
i, e := tableConfig.ReadFile(path)
|
||||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
if len(i) == 0 || strings.TrimSpace(string(i)) == "" {
|
||||
return nil
|
||||
}
|
||||
if strings.Contains(path, "data") {
|
||||
Instance.TablesInitData[tableName] = string(i)
|
||||
} else {
|
||||
Instance.Tables[tableName] = string(i)
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if Instance.Domain != "" && Instance.IsInit {
|
||||
IsInit = true
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user