update go.mod

This commit is contained in:
2024-03-10 14:21:37 +08:00
parent 232bc3835e
commit 42ad19e798
3 changed files with 64 additions and 32 deletions
+14 -11
View File
@@ -476,7 +476,7 @@ func SliceIn(slice interface{}, data interface{}) bool {
// Unmarshal 输出结果到结构体中
func (cfg *SysConf) Unmarshal(ins interface{}) error {
var structSet func(t reflect.Type, v reflect.Value,oriSeg string) error
var structSet func(t reflect.Type, v reflect.Value, oriSeg string) error
t := reflect.TypeOf(ins)
v := reflect.ValueOf(ins).Elem()
if v.Kind() != reflect.Struct {
@@ -486,7 +486,7 @@ func (cfg *SysConf) Unmarshal(ins interface{}) error {
return errors.New("Cannot Write!")
}
t = t.Elem()
structSet = func(t reflect.Type, v reflect.Value,oriSeg string) error {
structSet = func(t reflect.Type, v reflect.Value, oriSeg string) error {
for i := 0; i < t.NumField(); i++ {
tp := t.Field(i)
vl := v.Field(i)
@@ -494,13 +494,16 @@ func (cfg *SysConf) Unmarshal(ins interface{}) error {
continue
}
if vl.Type().Kind() == reflect.Struct {
structSet(vl.Type(), vl,tp.Tag.Get("seg"))
structSet(vl.Type(), vl, tp.Tag.Get("seg"))
continue
}
seg := tp.Tag.Get("seg")
key := tp.Tag.Get("key")
if oriSeg!="" {
seg=oriSeg
if key != "" && seg == "" && cfg.HaveSegMent {
seg = "unnamed"
}
if oriSeg != "" {
seg = oriSeg
}
if seg == "" || key == "" {
continue
@@ -529,12 +532,12 @@ func (cfg *SysConf) Unmarshal(ins interface{}) error {
}
return nil
}
return structSet(t, v,"")
return structSet(t, v, "")
}
// Marshal 输出结果到结构体中
func (cfg *SysConf) Marshal(ins interface{}) ([]byte, error) {
var structSet func(t reflect.Type, v reflect.Value,oriSeg string)
var structSet func(t reflect.Type, v reflect.Value, oriSeg string)
t := reflect.TypeOf(ins)
v := reflect.ValueOf(ins)
if v.Kind() != reflect.Struct {
@@ -544,20 +547,20 @@ func (cfg *SysConf) Marshal(ins interface{}) ([]byte, error) {
t = t.Elem()
v = v.Elem()
}
structSet = func(t reflect.Type, v reflect.Value,oriSeg string) {
structSet = func(t reflect.Type, v reflect.Value, oriSeg string) {
for i := 0; i < t.NumField(); i++ {
var seg, key, comment string = "", "", ""
tp := t.Field(i)
vl := v.Field(i)
if vl.Type().Kind() == reflect.Struct {
structSet(vl.Type(), vl,tp.Tag.Get("seg"))
structSet(vl.Type(), vl, tp.Tag.Get("seg"))
continue
}
seg = tp.Tag.Get("seg")
key = tp.Tag.Get("key")
comment = tp.Tag.Get("comment")
if oriSeg != "" {
seg=oriSeg
seg = oriSeg
}
if seg == "" || key == "" {
continue
@@ -569,7 +572,7 @@ func (cfg *SysConf) Marshal(ins interface{}) ([]byte, error) {
}
}
structSet(t, v,"")
structSet(t, v, "")
return cfg.Build(), nil
}