1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-29 23:36:25 -04:00
v2fly/tools/conf/dns.go

33 lines
672 B
Go
Raw Normal View History

2016-10-17 08:35:13 -04:00
package conf
import (
"v2ray.com/core/app/dns"
v2net "v2ray.com/core/common/net"
)
type DnsConfig struct {
Servers []*Address `json:"servers"`
Hosts map[string]*Address `json:"hosts"`
}
2016-11-27 15:39:09 -05:00
func (v *DnsConfig) Build() *dns.Config {
2016-10-17 08:35:13 -04:00
config := new(dns.Config)
2016-11-27 15:39:09 -05:00
config.NameServers = make([]*v2net.Endpoint, len(v.Servers))
for idx, server := range v.Servers {
2016-10-17 08:35:13 -04:00
config.NameServers[idx] = &v2net.Endpoint{
Network: v2net.Network_UDP,
Address: server.Build(),
Port: 53,
}
}
2016-11-27 15:39:09 -05:00
if v.Hosts != nil {
2016-10-17 08:35:13 -04:00
config.Hosts = make(map[string]*v2net.IPOrDomain)
2016-11-27 15:39:09 -05:00
for domain, ip := range v.Hosts {
2016-11-27 11:01:44 -05:00
config.Hosts[domain] = ip.Build()
2016-10-17 08:35:13 -04:00
}
}
return config
}