1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-20 22:45:24 +00:00
v2fly/proxy/dokodemo/config_json.go

38 lines
1001 B
Go
Raw Normal View History

// +build json
package dokodemo
import (
"encoding/json"
2016-06-11 20:52:37 +00:00
"errors"
2016-08-20 18:55:45 +00:00
v2net "v2ray.com/core/common/net"
"v2ray.com/core/proxy/registry"
)
2016-06-10 20:26:39 +00:00
func (this *Config) UnmarshalJSON(data []byte) error {
type DokodemoConfig struct {
Host *v2net.AddressJson `json:"address"`
PortValue v2net.Port `json:"port"`
NetworkList *v2net.NetworkList `json:"network"`
TimeoutValue int `json:"timeout"`
2016-06-11 23:30:56 +00:00
Redirect bool `json:"followRedirect"`
2016-06-10 20:26:39 +00:00
}
rawConfig := new(DokodemoConfig)
if err := json.Unmarshal(data, rawConfig); err != nil {
2016-06-11 20:52:37 +00:00
return errors.New("Dokodemo: Failed to parse config: " + err.Error())
2016-06-10 20:26:39 +00:00
}
2016-06-12 20:54:33 +00:00
if rawConfig.Host != nil {
this.Address = rawConfig.Host.Address
}
2016-06-10 20:26:39 +00:00
this.Port = rawConfig.PortValue
this.Network = rawConfig.NetworkList
this.Timeout = rawConfig.TimeoutValue
2016-06-11 23:30:56 +00:00
this.FollowRedirect = rawConfig.Redirect
2016-06-10 20:26:39 +00:00
return nil
}
func init() {
registry.RegisterInboundConfig("dokodemo-door", func() interface{} { return new(Config) })
}