feat: add default value and required to outline file

This commit is contained in:
mzz2017 2023-03-02 15:25:47 +08:00
parent f3845bd452
commit 87c9b9d6a5
2 changed files with 20 additions and 15 deletions

View File

@ -21,8 +21,9 @@ type Global struct {
UdpCheckDns string `mapstructure:"udp_check_dns" default:"dns.google:53"` UdpCheckDns string `mapstructure:"udp_check_dns" default:"dns.google:53"`
CheckInterval time.Duration `mapstructure:"check_interval" default:"30s"` CheckInterval time.Duration `mapstructure:"check_interval" default:"30s"`
CheckTolerance time.Duration `mapstructure:"check_tolerance" default:"0"` CheckTolerance time.Duration `mapstructure:"check_tolerance" default:"0"`
DnsUpstream string `mapstructure:"dns_upstream" default:"<empty>"` // Deprecated:
LanInterface []string `mapstructure:"lan_interface"` DnsUpstream string `mapstructure:"dns_upstream" default:"<empty>"`
LanInterface []string `mapstructure:"lan_interface"`
// Deprecated: // Deprecated:
LanNatDirect bool `mapstructure:"lan_nat_direct" default:"false"` LanNatDirect bool `mapstructure:"lan_nat_direct" default:"false"`
WanInterface []string `mapstructure:"wan_interface"` WanInterface []string `mapstructure:"wan_interface"`

View File

@ -18,13 +18,14 @@ type Outline struct {
} }
type OutlineElem struct { type OutlineElem struct {
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Mapping string `json:"mapping,omitempty"` Mapping string `json:"mapping,omitempty"`
IsArray bool `json:"isArray,omitempty"` IsArray bool `json:"isArray,omitempty"`
Type string `json:"type,omitempty"` DefaultValue string `json:"defaultValue,omitempty"`
ElemType string `json:"elemType,omitempty"` Required bool `json:"required,omitempty"`
Desc string `json:"desc,omitempty"` Type string `json:"type,omitempty"`
Structure []*OutlineElem `json:"structure,omitempty"` Desc string `json:"desc,omitempty"`
Structure []*OutlineElem `json:"structure,omitempty"`
} }
func ExportOutline(version string) *Outline { func ExportOutline(version string) *Outline {
@ -101,13 +102,16 @@ func (e *outlineExporter) exportStruct(t reflect.Type, descSource Desc, inheritS
// Record leaves. // Record leaves.
e.leaves[typ.String()] = typ e.leaves[typ.String()] = typ
} }
_, required := section.Tag.Lookup("required")
outlines = append(outlines, &OutlineElem{ outlines = append(outlines, &OutlineElem{
Name: section.Name, Name: section.Name,
Mapping: section.Tag.Get("mapstructure"), Mapping: section.Tag.Get("mapstructure"),
IsArray: isArray, IsArray: isArray,
Type: typ.String(), DefaultValue: section.Tag.Get("default"),
Desc: desc, Required: required,
Structure: children, Type: typ.String(),
Desc: desc,
Structure: children,
}) })
} }
return outlines return outlines