1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-10-01 08:16:00 -04:00
v2fly/app/dns/config_json.go

35 lines
715 B
Go
Raw Normal View History

2016-01-15 09:23:12 -05:00
// +build json
2016-05-16 03:25:34 -04:00
package dns
2016-01-15 09:23:12 -05:00
import (
"encoding/json"
2016-08-20 14:55:45 -04:00
v2net "v2ray.com/core/common/net"
2016-01-15 09:23:12 -05:00
)
2016-05-16 02:09:28 -04:00
func (this *Config) UnmarshalJSON(data []byte) error {
type JsonConfig struct {
2016-09-20 10:05:35 -04:00
Servers []*v2net.AddressPB `json:"servers"`
Hosts map[string]*v2net.AddressPB `json:"hosts"`
2016-01-15 09:23:12 -05:00
}
2016-05-16 02:09:28 -04:00
jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
2016-01-15 09:23:12 -05:00
}
2016-09-20 10:05:35 -04:00
this.NameServers = make([]*v2net.DestinationPB, len(jsonConfig.Servers))
2016-05-16 02:09:28 -04:00
for idx, server := range jsonConfig.Servers {
2016-09-20 10:05:35 -04:00
this.NameServers[idx] = &v2net.DestinationPB{
Network: v2net.Network_UDP,
Address: server,
Port: 53,
}
2016-01-15 09:23:12 -05:00
}
2016-05-16 02:09:28 -04:00
2016-05-22 16:30:08 -04:00
if jsonConfig.Hosts != nil {
2016-09-20 10:05:35 -04:00
this.Hosts = jsonConfig.Hosts
2016-05-22 16:30:08 -04:00
}
2016-01-15 09:23:12 -05:00
return nil
}