mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2026-01-06 03:55:48 +08:00
实现基本的匹配条件管理
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package condutils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
_ "github.com/iwind/TeaGo/bootstrap"
|
||||
"github.com/iwind/TeaGo/files"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type CondJSComponent struct {
|
||||
Type string `json:"type"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Component string `json:"component"`
|
||||
}
|
||||
|
||||
// 读取所有可用的条件
|
||||
func ReadAllAvailableCondTypes() []*CondJSComponent {
|
||||
result := []*CondJSComponent{}
|
||||
|
||||
dir := Tea.Root + "/web/"
|
||||
if Tea.IsTesting() {
|
||||
dir = filepath.Dir(Tea.Root) + "/web"
|
||||
}
|
||||
dir += "/public/js/conds/"
|
||||
jsonFiles := files.NewFile(dir).List()
|
||||
for _, file := range jsonFiles {
|
||||
if file.Ext() == ".json" {
|
||||
data, err := file.ReadAll()
|
||||
if err != nil {
|
||||
logs.Println("[COND]read data from json file: " + err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
c := []*CondJSComponent{}
|
||||
err = json.Unmarshal(data, &c)
|
||||
if err != nil {
|
||||
logs.Println("[COND]decode json failed: " + err.Error())
|
||||
continue
|
||||
}
|
||||
result = append(result, c...)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package condutils
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestReadAllAvailableCondTypes(t *testing.T) {
|
||||
t.Log(ReadAllAvailableCondTypes())
|
||||
}
|
||||
Reference in New Issue
Block a user