chore: refine config unmarshal

This commit is contained in:
cubemaze 2023-08-26 10:57:54 +08:00
parent cb868c7411
commit bb16015dab

View File

@ -33,9 +33,9 @@ type Options struct {
CertConfig *CertConfig `json:"CertConfig"` CertConfig *CertConfig `json:"CertConfig"`
} }
func (n *NodeConfig) UnmarshalJSON(b []byte) (err error) { func (n *NodeConfig) UnmarshalJSON(data []byte) (err error) {
r := rawNodeConfig{} r := rawNodeConfig{}
err = json.Unmarshal(b, &r) err = json.Unmarshal(data, &r)
if err != nil { if err != nil {
return err return err
} }
@ -48,14 +48,14 @@ func (n *NodeConfig) UnmarshalJSON(b []byte) (err error) {
n.ApiConfig = ApiConfig{ n.ApiConfig = ApiConfig{
Timeout: 30, Timeout: 30,
} }
err = json.Unmarshal(b, &n.ApiConfig) err = json.Unmarshal(data, &n.ApiConfig)
if err != nil { if err != nil {
return return
} }
} }
if r.OptRaw != nil { if r.OptRaw != nil {
err = json.Unmarshal(*r.OptRaw, &n.Options) data = *r.OptRaw
err = json.Unmarshal(data, &n.Options)
if err != nil { if err != nil {
return return
} }
@ -65,18 +65,18 @@ func (n *NodeConfig) UnmarshalJSON(b []byte) (err error) {
ListenIP: "0.0.0.0", ListenIP: "0.0.0.0",
SendIP: "0.0.0.0", SendIP: "0.0.0.0",
} }
err = json.Unmarshal(b, &n.Options) err = json.Unmarshal(data, &n.Options)
if err != nil { if err != nil {
return return
} }
}
switch n.Options.Core { switch n.Options.Core {
case "xray": case "xray":
n.Options.XrayOptions = NewXrayOptions() n.Options.XrayOptions = NewXrayOptions()
return json.Unmarshal(b, n.Options.XrayOptions) return json.Unmarshal(data, n.Options.XrayOptions)
case "sing": case "sing":
n.Options.SingOptions = NewSingOptions() n.Options.SingOptions = NewSingOptions()
return json.Unmarshal(b, n.Options.SingOptions) return json.Unmarshal(data, n.Options.SingOptions)
}
} }
return return
} }