Chore: support MarshalYAML to some config filed (#581)

This commit is contained in:
Kaming Chan 2020-03-15 19:40:39 +08:00 committed by GitHub
parent 9471d80785
commit 082847b403
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 3 deletions

View file

@ -11,7 +11,6 @@ import (
"github.com/Dreamacro/clash/log" "github.com/Dreamacro/clash/log"
D "github.com/miekg/dns" D "github.com/miekg/dns"
yaml "gopkg.in/yaml.v2"
) )
var ( var (
@ -46,8 +45,8 @@ func (e *EnhancedMode) UnmarshalYAML(unmarshal func(interface{}) error) error {
} }
// MarshalYAML serialize EnhancedMode with yaml // MarshalYAML serialize EnhancedMode with yaml
func (e EnhancedMode) MarshalYAML() ([]byte, error) { func (e EnhancedMode) MarshalYAML() (interface{}, error) {
return yaml.Marshal(e.String()) return e.String(), nil
} }
// UnmarshalJSON unserialize EnhancedMode with json // UnmarshalJSON unserialize EnhancedMode with json

View file

@ -55,6 +55,11 @@ func (l LogLevel) MarshalJSON() ([]byte, error) {
return json.Marshal(l.String()) return json.Marshal(l.String())
} }
// MarshalYAML serialize LogLevel with yaml
func (l LogLevel) MarshalYAML() (interface{}, error) {
return l.String(), nil
}
func (l LogLevel) String() string { func (l LogLevel) String() string {
switch l { switch l {
case INFO: case INFO:

View file

@ -51,6 +51,11 @@ func (m TunnelMode) MarshalJSON() ([]byte, error) {
return json.Marshal(m.String()) return json.Marshal(m.String())
} }
// MarshalYAML serialize TunnelMode with yaml
func (m TunnelMode) MarshalYAML() (interface{}, error) {
return m.String(), nil
}
func (m TunnelMode) String() string { func (m TunnelMode) String() string {
switch m { switch m {
case Global: case Global: