1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-25 00:45:24 +00:00
v2fly/app/router/config_json.go

29 lines
641 B
Go
Raw Normal View History

2016-01-17 15:20:49 +00:00
// +build json
package router
import (
"encoding/json"
"github.com/v2ray/v2ray-core/common/log"
)
func (this *Config) UnmarshalJSON(data []byte) error {
type JsonConfig struct {
Strategy string `json:"strategy"`
Settings json.RawMessage `json:"settings"`
}
jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
}
settings, err := CreateRouterConfig(jsonConfig.Strategy, []byte(jsonConfig.Settings))
if err != nil {
2016-01-18 11:24:33 +00:00
log.Error("Router: Failed to load router settings: ", err)
2016-01-17 15:20:49 +00:00
return err
}
this.Strategy = jsonConfig.Strategy
this.Settings = settings
return nil
}