mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-25 07:20:44 +00:00
unified config loader
This commit is contained in:
1 parent
3f7b70a465
commit
e732ba62a6
18 files changed
+257
-215
No files matched your search
@@ -6,27 +6,27 @@ import (
|
||||
"encoding/json"
|
||||
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"github.com/v2ray/v2ray-core/proxy/internal/config"
|
||||
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||
)
|
||||
|
||||
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"`
|
||||
}
|
||||
rawConfig := new(DokodemoConfig)
|
||||
if err := json.Unmarshal(data, rawConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
this.Address = rawConfig.Host.Address
|
||||
this.Port = rawConfig.PortValue
|
||||
this.Network = rawConfig.NetworkList
|
||||
this.Timeout = rawConfig.TimeoutValue
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
config.RegisterInboundConfig("dokodemo-door",
|
||||
func(data []byte) (interface{}, error) {
|
||||
type DokodemoConfig struct {
|
||||
Host *v2net.AddressJson `json:"address"`
|
||||
PortValue v2net.Port `json:"port"`
|
||||
NetworkList *v2net.NetworkList `json:"network"`
|
||||
TimeoutValue int `json:"timeout"`
|
||||
}
|
||||
rawConfig := new(DokodemoConfig)
|
||||
if err := json.Unmarshal(data, rawConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Config{
|
||||
Address: rawConfig.Host.Address,
|
||||
Port: rawConfig.PortValue,
|
||||
Network: rawConfig.NetworkList,
|
||||
Timeout: rawConfig.TimeoutValue,
|
||||
}, nil
|
||||
})
|
||||
internal.RegisterInboundConfig("dokodemo-door", func() interface{} { return new(Config) })
|
||||
}
|
||||
Reference in new issue
Block a user