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
|
|
|
|
}
|