mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-11-19 02:46:33 -05:00
29 lines
628 B
Go
29 lines
628 B
Go
// +build json
|
|
|
|
package router
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"v2ray.com/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 {
|
|
log.Error("Router: Failed to load router settings: ", err)
|
|
return err
|
|
}
|
|
this.Strategy = jsonConfig.Strategy
|
|
this.Settings = settings
|
|
return nil
|
|
}
|