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