26 lines
482 B
Go
26 lines
482 B
Go
package data
|
|
|
|
import "net"
|
|
|
|
type HardwareAddr net.HardwareAddr
|
|
|
|
//MarshalJSON to bytearray
|
|
func (a HardwareAddr) String() string {
|
|
return net.HardwareAddr(a).String()
|
|
}
|
|
|
|
//MarshalJSON to bytearray
|
|
func (a HardwareAddr) MarshalText() ([]byte, error) {
|
|
return []byte(a.String()), nil
|
|
}
|
|
|
|
// UnmarshalJSON from bytearray
|
|
func (a HardwareAddr) UnmarshalText(data []byte) error {
|
|
b, err := net.ParseMAC(string(data))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
a = HardwareAddr(b)
|
|
return nil
|
|
}
|