1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 18:17:52 -05:00
v2fly/proxy/vmess/inbound/config_json.go

58 lines
1.3 KiB
Go
Raw Normal View History

// +build json
package inbound
import (
"encoding/json"
"github.com/v2ray/v2ray-core/proxy/internal/config"
"github.com/v2ray/v2ray-core/proxy/vmess"
)
2016-01-18 19:21:07 -05:00
func (this *DetourConfig) UnmarshalJSON(data []byte) error {
type JsonDetourConfig struct {
ToTag string `json:"to"`
}
jsonConfig := new(JsonDetourConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
}
this.ToTag = jsonConfig.ToTag
return nil
}
func (this *FeaturesConfig) UnmarshalJSON(data []byte) error {
type JsonFeaturesConfig struct {
Detour *DetourConfig `json:"detour"`
}
jsonConfig := new(JsonFeaturesConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
}
this.Detour = jsonConfig.Detour
return nil
}
func (this *Config) UnmarshalJSON(data []byte) error {
type JsonConfig struct {
Users []*vmess.User `json:"clients"`
Features *FeaturesConfig `json:"features"`
}
jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
}
this.AllowedUsers = jsonConfig.Users
this.Features = jsonConfig.Features
return nil
}
func init() {
config.RegisterInboundConnectionConfig("vmess",
func(data []byte) (interface{}, error) {
2016-01-18 19:21:07 -05:00
config := new(Config)
err := json.Unmarshal(data, config)
return config, err
})
}