Chore: mode use lower case (backward compatible)

This commit is contained in:
Dreamacro 2020-06-01 00:32:37 +08:00
parent 71d30e6654
commit 46244a6496
2 changed files with 8 additions and 7 deletions

View File

@ -92,8 +92,8 @@ allow-lan: false
# "[aaaa::a8aa:ff:fe09:57d8]": bind a single IPv6 address
# bind-address: "*"
# Rule / Global / Direct (default is Rule)
mode: Rule
# rule / global / direct (default is rule)
mode: rule
# set log level to stdout (default is info)
# info / warning / error / debug / silent

View File

@ -3,6 +3,7 @@ package tunnel
import (
"encoding/json"
"errors"
"strings"
)
type TunnelMode int
@ -26,7 +27,7 @@ const (
func (m *TunnelMode) UnmarshalJSON(data []byte) error {
var tp string
json.Unmarshal(data, &tp)
mode, exist := ModeMapping[tp]
mode, exist := ModeMapping[strings.ToLower(tp)]
if !exist {
return errors.New("invalid mode")
}
@ -38,7 +39,7 @@ func (m *TunnelMode) UnmarshalJSON(data []byte) error {
func (m *TunnelMode) UnmarshalYAML(unmarshal func(interface{}) error) error {
var tp string
unmarshal(&tp)
mode, exist := ModeMapping[tp]
mode, exist := ModeMapping[strings.ToLower(tp)]
if !exist {
return errors.New("invalid mode")
}
@ -59,11 +60,11 @@ func (m TunnelMode) MarshalYAML() (interface{}, error) {
func (m TunnelMode) String() string {
switch m {
case Global:
return "Global"
return "global"
case Rule:
return "Rule"
return "rule"
case Direct:
return "Direct"
return "direct"
default:
return "Unknown"
}