2014-08-10 01:12:52 +00:00
|
|
|
package opts
|
|
|
|
|
|
|
|
import (
|
2014-08-10 03:50:46 +00:00
|
|
|
"fmt"
|
2014-08-10 01:12:52 +00:00
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
2015-07-12 08:33:30 +00:00
|
|
|
// IpOpt type that hold an IP
|
2014-08-10 01:12:52 +00:00
|
|
|
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 {
|
2014-08-10 03:50:46 +00:00
|
|
|
ip := net.ParseIP(val)
|
|
|
|
if ip == nil {
|
2014-08-13 06:45:40 +00:00
|
|
|
return fmt.Errorf("%s is not an ip address", val)
|
2014-08-10 03:50:46 +00:00
|
|
|
}
|
2015-06-05 16:44:10 +00:00
|
|
|
*o.IP = ip
|
2014-08-10 01:12:52 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *IpOpt) String() string {
|
2015-06-11 07:53:39 +00:00
|
|
|
if *o.IP == nil {
|
|
|
|
return ""
|
|
|
|
}
|
2015-06-05 16:44:10 +00:00
|
|
|
return o.IP.String()
|
2014-08-10 01:12:52 +00:00
|
|
|
}
|