1
0
mirror of https://github.com/docker/cli.git synced 2026-01-26 15:41:42 +03:00
Files
cli/opts/ip.go
Solomon Hykes 561b98067f Fix inconsistency in IP address parsing errors
Signed-off-by: Solomon Hykes <solomon@docker.com>
2017-05-15 11:57:12 +02:00

32 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()
}