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