From 46244a649699028563e347264f3639c0b9010b44 Mon Sep 17 00:00:00 2001 From: Dreamacro <305009791@qq.com> Date: Mon, 1 Jun 2020 00:32:37 +0800 Subject: [PATCH] Chore: `mode` use lower case (backward compatible) --- README.md | 4 ++-- tunnel/mode.go | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index fa72efdb..d069e87f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/tunnel/mode.go b/tunnel/mode.go index 655c9f57..6e07a060 100644 --- a/tunnel/mode.go +++ b/tunnel/mode.go @@ -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" }