1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-30 19:15:23 +00:00
v2fly/common/net/address_json.go
2016-01-15 13:17:04 +01:00

27 lines
401 B
Go

// +build json
package net
import (
"encoding/json"
"net"
)
type AddressJson struct {
Address Address
}
func (this *AddressJson) UnmarshalJSON(data []byte) error {
var rawStr string
if err := json.Unmarshal(data, &rawStr); err != nil {
return err
}
ip := net.ParseIP(rawStr)
if ip != nil {
this.Address = IPAddress(ip)
} else {
this.Address = DomainAddress(rawStr)
}
return nil
}