1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/opts/ip.go
Solomon Hykes a30fd7a962 Fix inconsistency in IP address parsing errors
Signed-off-by: Solomon Hykes <solomon@docker.com>
2014-08-13 19:25:51 +00:00

31 lines
426 B
Go

package opts
import (
"fmt"
"net"
)
type IpOpt struct {
*net.IP
}
func NewIpOpt(ref *net.IP, defaultVal string) *IpOpt {
o := &IpOpt{
IP: ref,
}
o.Set(defaultVal)
return o
}
func (o *IpOpt) Set(val string) error {
ip := net.ParseIP(val)
if ip == nil {
return fmt.Errorf("%s is not an ip address", val)
}
(*o.IP) = net.ParseIP(val)
return nil
}
func (o *IpOpt) String() string {
return (*o.IP).String()
}