Chore: mode
use lower case (backward compatible)
This commit is contained in:
parent
a59e3feba9
commit
1849fe0974
2 changed files with 8 additions and 7 deletions
|
@ -92,8 +92,8 @@ allow-lan: false
|
||||||
# "[aaaa::a8aa:ff:fe09:57d8]": bind a single IPv6 address
|
# "[aaaa::a8aa:ff:fe09:57d8]": bind a single IPv6 address
|
||||||
# bind-address: "*"
|
# bind-address: "*"
|
||||||
|
|
||||||
# Rule / Global / Direct (default is Rule)
|
# rule / global / direct (default is rule)
|
||||||
mode: Rule
|
mode: rule
|
||||||
|
|
||||||
# set log level to stdout (default is info)
|
# set log level to stdout (default is info)
|
||||||
# info / warning / error / debug / silent
|
# info / warning / error / debug / silent
|
||||||
|
|
|
@ -3,6 +3,7 @@ package tunnel
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TunnelMode int
|
type TunnelMode int
|
||||||
|
@ -26,7 +27,7 @@ const (
|
||||||
func (m *TunnelMode) UnmarshalJSON(data []byte) error {
|
func (m *TunnelMode) UnmarshalJSON(data []byte) error {
|
||||||
var tp string
|
var tp string
|
||||||
json.Unmarshal(data, &tp)
|
json.Unmarshal(data, &tp)
|
||||||
mode, exist := ModeMapping[tp]
|
mode, exist := ModeMapping[strings.ToLower(tp)]
|
||||||
if !exist {
|
if !exist {
|
||||||
return errors.New("invalid mode")
|
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 {
|
func (m *TunnelMode) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
var tp string
|
var tp string
|
||||||
unmarshal(&tp)
|
unmarshal(&tp)
|
||||||
mode, exist := ModeMapping[tp]
|
mode, exist := ModeMapping[strings.ToLower(tp)]
|
||||||
if !exist {
|
if !exist {
|
||||||
return errors.New("invalid mode")
|
return errors.New("invalid mode")
|
||||||
}
|
}
|
||||||
|
@ -59,11 +60,11 @@ func (m TunnelMode) MarshalYAML() (interface{}, error) {
|
||||||
func (m TunnelMode) String() string {
|
func (m TunnelMode) String() string {
|
||||||
switch m {
|
switch m {
|
||||||
case Global:
|
case Global:
|
||||||
return "Global"
|
return "global"
|
||||||
case Rule:
|
case Rule:
|
||||||
return "Rule"
|
return "rule"
|
||||||
case Direct:
|
case Direct:
|
||||||
return "Direct"
|
return "direct"
|
||||||
default:
|
default:
|
||||||
return "Unknown"
|
return "Unknown"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue