Feature: add custom DNS support (#56)

This commit is contained in:
Dreamacro
2018-12-05 21:13:29 +08:00
committed by GitHub
parent da5db36ccf
commit 03c249ecb1
23 changed files with 939 additions and 124 deletions

View File

@ -10,9 +10,9 @@ type Mode int
var (
// ModeMapping is a mapping for Mode enum
ModeMapping = map[string]Mode{
"Global": Global,
"Rule": Rule,
"Direct": Direct,
Global.String(): Global,
Rule.String(): Rule,
Direct.String(): Direct,
}
)
@ -34,6 +34,18 @@ func (m *Mode) UnmarshalJSON(data []byte) error {
return nil
}
// UnmarshalYAML unserialize Mode with yaml
func (m *Mode) UnmarshalYAML(unmarshal func(interface{}) error) error {
var tp string
unmarshal(&tp)
mode, exist := ModeMapping[tp]
if !exist {
return errors.New("invalid mode")
}
*m = mode
return nil
}
// MarshalJSON serialize Mode
func (m Mode) MarshalJSON() ([]byte, error) {
return json.Marshal(m.String())