mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
opts.IpOpt: a helper to parse IP addressed from the command line
Signed-off-by: Solomon Hykes <solomon@docker.com>
This commit is contained in:
parent
a4befff533
commit
6d59a56675
1 changed files with 28 additions and 0 deletions
28
opts/ip.go
Normal file
28
opts/ip.go
Normal 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()
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue