github.com/gunjan5/docker@v1.8.2/opts/ip.go (about) 1 package opts 2 3 import ( 4 "fmt" 5 "net" 6 ) 7 8 // IpOpt type that hold an IP 9 type IpOpt struct { 10 *net.IP 11 } 12 13 func NewIpOpt(ref *net.IP, defaultVal string) *IpOpt { 14 o := &IpOpt{ 15 IP: ref, 16 } 17 o.Set(defaultVal) 18 return o 19 } 20 21 func (o *IpOpt) Set(val string) error { 22 ip := net.ParseIP(val) 23 if ip == nil { 24 return fmt.Errorf("%s is not an ip address", val) 25 } 26 *o.IP = ip 27 return nil 28 } 29 30 func (o *IpOpt) String() string { 31 if *o.IP == nil { 32 return "" 33 } 34 return o.IP.String() 35 }