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

28 lines
477 B
Go
Raw Normal View History

2016-01-15 07:17:04 -05:00
// +build json
package net
import (
"encoding/json"
)
2016-08-26 18:04:35 -04:00
func (this *AddressPB) UnmarshalJSON(data []byte) error {
2016-01-15 07:17:04 -05:00
var rawStr string
if err := json.Unmarshal(data, &rawStr); err != nil {
return err
}
2016-08-26 18:04:35 -04:00
addr := ParseAddress(rawStr)
switch addr.Family() {
case AddressFamilyIPv4, AddressFamilyIPv6:
this.Address = &AddressPB_Ip{
Ip: []byte(addr.IP()),
}
case AddressFamilyDomain:
this.Address = &AddressPB_Domain{
Domain: addr.Domain(),
}
}
2016-01-15 07:17:04 -05:00
return nil
}