diff --git a/planner/configexport/example/EasyConfig.json b/planner/configexport/example/EasyConfig.json index 79f1fe2..e12622a 100644 --- a/planner/configexport/example/EasyConfig.json +++ b/planner/configexport/example/EasyConfig.json @@ -6,8 +6,8 @@ }, "Other": { "0": { - "id": 1, - "name": "张飞" + "name": "张飞", + "id": 1 }, "1": { "id": 2, diff --git a/planner/configexport/example/IndexConfig.json b/planner/configexport/example/IndexConfig.json index 7294fdd..0ac28e5 100644 --- a/planner/configexport/example/IndexConfig.json +++ b/planner/configexport/example/IndexConfig.json @@ -1,58 +1,58 @@ { "1": { "b": { - "Award": { - "0": "asd", - "1": "12" - }, - "Other": { - "0": { - "name": "张飞", - "id": 1 - }, - "1": { - "name": "刘备", - "id": 2 - } - }, "Id": 1, - "Count": "b" - } - }, - "2": { - "c": { + "Count": "b", "Award": { "0": "asd", "1": "12" }, - "Other": { - "0": { - "name": "张飞", - "id": 1 - }, - "1": { - "id": 2, - "name": "刘备" - } - }, - "Id": 2, - "Count": "c" - }, - "d": { - "Id": 2, - "Count": "d", - "Award": { - "1": "12", - "0": "asd" - }, "Other": { "0": { "id": 1, "name": "张飞" }, + "1": { + "name": "刘备", + "id": 2 + } + } + } + }, + "2": { + "c": { + "Other": { + "0": { + "id": 1, + "name": "张飞" + }, + "1": { + "name": "刘备", + "id": 2 + } + }, + "Id": 2, + "Count": "c", + "Award": { + "0": "asd", + "1": "12" + } + }, + "d": { + "Id": 2, + "Count": "d", + "Award": { + "0": "asd", + "1": "12" + }, + "Other": { "1": { "id": 2, "name": "刘备" + }, + "0": { + "id": 1, + "name": "张飞" } } } diff --git a/planner/configexport/example/config.go b/planner/configexport/example/config.go index 8c7d4c3..fae0ca4 100644 --- a/planner/configexport/example/config.go +++ b/planner/configexport/example/config.go @@ -9,6 +9,7 @@ import ( ) var json = jsonIter.ConfigCompatibleWithStandardLibrary +var full map[string]any var ( // IndexConfig 有索引 IndexConfig map[int]map[string]*IndexConfigDefine @@ -32,11 +33,16 @@ func LoadConfig(handle func(filename string, config any) error) { } +// Refresh 将加载后的配置刷新到线上 func Refresh() { + full = make(map[string]any) IndexConfig = _IndexConfig + full["IndexConfig"] = IndexConfig EasyConfig = _EasyConfig + full["EasyConfig"] = EasyConfig } +// DefaultLoad 默认提供的配置加载函数 func DefaultLoad(filepath string) { LoadConfig(func(filename string, config any) error { bytes, err := os.ReadFile(filepath) @@ -47,3 +53,9 @@ func DefaultLoad(filepath string) { return json.Unmarshal(bytes, &config) }) } + +// GetFull 获取所有配置的 map 集合 +// - 通常用于前端配置通过后端接口获取的情况 +func GetFull() map[string]any { + return full +} diff --git a/planner/configexport/internal/template.go b/planner/configexport/internal/template.go index fe1a194..4862648 100644 --- a/planner/configexport/internal/template.go +++ b/planner/configexport/internal/template.go @@ -41,6 +41,7 @@ import ( ) var json = jsonIter.ConfigCompatibleWithStandardLibrary +var full map[string]any var ( {{range $index, $config := .Configs}} @@ -66,13 +67,16 @@ func LoadConfig(handle func(filename string, config any) error) { {{end}} } +// Refresh 将加载后的配置刷新到线上 func Refresh() { + full = make(map[string]any) {{range $index, $config := .Configs}} {{$config.Name}} = _{{$config.Name}} + full["{{$config.Name}}"] = {{$config.Name}} {{end}} } - +// DefaultLoad 默认提供的配置加载函数 func DefaultLoad(filepath string) { LoadConfig(func(filename string, config any) error { bytes, err := os.ReadFile(filepath) @@ -82,6 +86,12 @@ func DefaultLoad(filepath string) { return json.Unmarshal(bytes, &config) }) } + +// GetFull 获取所有配置的 map 集合 +// - 通常用于前端配置通过后端接口获取的情况 +func GetFull() map[string]any { + return full +} ` GenerateGoDefineTemplate = `// Code generated by minotaur-config-export. DO NOT EDIT.