config_json.go 546 B

12345678910111213141516171819202122232425
  1. // +build json
  2. package dns
  3. import (
  4. "encoding/json"
  5. v2net "github.com/v2ray/v2ray-core/common/net"
  6. )
  7. func (this *Config) UnmarshalJSON(data []byte) error {
  8. type JsonConfig struct {
  9. Servers []v2net.Address `json:"servers"`
  10. }
  11. jsonConfig := new(JsonConfig)
  12. if err := json.Unmarshal(data, jsonConfig); err != nil {
  13. return err
  14. }
  15. this.NameServers = make([]v2net.Destination, len(jsonConfig.Servers))
  16. for idx, server := range jsonConfig.Servers {
  17. this.NameServers[idx] = v2net.UDPDestination(server, v2net.Port(53))
  18. }
  19. return nil
  20. }