opts.IpOpt: a helper to parse IP addressed from the command line

Signed-off-by: Solomon Hykes <solomon@docker.com>
Upstream-commit: 6d59a566759da5729d7eb89a8e1888fc612f03cf
Component: engine
This commit is contained in:
Solomon Hykes
2014-08-10 01:12:52 +00:00
parent ec374f9227
commit a2a8fb8a10

View File

@ -0,0 +1,28 @@
package opts
import (
"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 {
// FIXME: return a parse error if the value is not a valid IP?
// We are not changing this now to preserve behavior while refactoring.
(*o.IP) = net.ParseIP(val)
return nil
}
func (o *IpOpt) String() string {
return (*o.IP).String()
}