mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-30 12:31:31 +00:00
Make type check strict
This commit is contained in:
parent
bc2d73b2d6
commit
2f4f4e18ee
|
@ -109,6 +109,8 @@ func (h *Inbound) UnmarshalJSON(bytes []byte) error {
|
||||||
v = &h.TUICOptions
|
v = &h.TUICOptions
|
||||||
case C.TypeHysteria2:
|
case C.TypeHysteria2:
|
||||||
v = &h.Hysteria2Options
|
v = &h.Hysteria2Options
|
||||||
|
case "":
|
||||||
|
return E.New("missing inbound type")
|
||||||
default:
|
default:
|
||||||
return E.New("unknown inbound type: ", h.Type)
|
return E.New("unknown inbound type: ", h.Type)
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,6 +119,8 @@ func (h *Outbound) UnmarshalJSON(bytes []byte) error {
|
||||||
v = &h.SelectorOptions
|
v = &h.SelectorOptions
|
||||||
case C.TypeURLTest:
|
case C.TypeURLTest:
|
||||||
v = &h.URLTestOptions
|
v = &h.URLTestOptions
|
||||||
|
case "":
|
||||||
|
return E.New("missing outbound type")
|
||||||
default:
|
default:
|
||||||
return E.New("unknown outbound type: ", h.Type)
|
return E.New("unknown outbound type: ", h.Type)
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,8 @@ func (o ACMEDNS01ChallengeOptions) MarshalJSON() ([]byte, error) {
|
||||||
v = o.AliDNSOptions
|
v = o.AliDNSOptions
|
||||||
case C.DNSProviderCloudflare:
|
case C.DNSProviderCloudflare:
|
||||||
v = o.CloudflareOptions
|
v = o.CloudflareOptions
|
||||||
|
case "":
|
||||||
|
return nil, E.New("missing provider type")
|
||||||
default:
|
default:
|
||||||
return nil, E.New("unknown provider type: " + o.Provider)
|
return nil, E.New("unknown provider type: " + o.Provider)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type _V2RayTransportOptions struct {
|
type _V2RayTransportOptions struct {
|
||||||
Type string `json:"type,omitempty"`
|
Type string `json:"type"`
|
||||||
HTTPOptions V2RayHTTPOptions `json:"-"`
|
HTTPOptions V2RayHTTPOptions `json:"-"`
|
||||||
WebsocketOptions V2RayWebsocketOptions `json:"-"`
|
WebsocketOptions V2RayWebsocketOptions `json:"-"`
|
||||||
QUICOptions V2RayQUICOptions `json:"-"`
|
QUICOptions V2RayQUICOptions `json:"-"`
|
||||||
|
@ -20,8 +20,6 @@ type V2RayTransportOptions _V2RayTransportOptions
|
||||||
func (o V2RayTransportOptions) MarshalJSON() ([]byte, error) {
|
func (o V2RayTransportOptions) MarshalJSON() ([]byte, error) {
|
||||||
var v any
|
var v any
|
||||||
switch o.Type {
|
switch o.Type {
|
||||||
case "":
|
|
||||||
return nil, nil
|
|
||||||
case C.V2RayTransportTypeHTTP:
|
case C.V2RayTransportTypeHTTP:
|
||||||
v = o.HTTPOptions
|
v = o.HTTPOptions
|
||||||
case C.V2RayTransportTypeWebsocket:
|
case C.V2RayTransportTypeWebsocket:
|
||||||
|
@ -32,6 +30,8 @@ func (o V2RayTransportOptions) MarshalJSON() ([]byte, error) {
|
||||||
v = o.GRPCOptions
|
v = o.GRPCOptions
|
||||||
case C.V2RayTransportTypeHTTPUpgrade:
|
case C.V2RayTransportTypeHTTPUpgrade:
|
||||||
v = o.HTTPUpgradeOptions
|
v = o.HTTPUpgradeOptions
|
||||||
|
case "":
|
||||||
|
return nil, E.New("missing transport type")
|
||||||
default:
|
default:
|
||||||
return nil, E.New("unknown transport type: " + o.Type)
|
return nil, E.New("unknown transport type: " + o.Type)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue