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"
|
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2014-08-09 21:12:52 -04:00
|
|
|
(*o.IP) = net.ParseIP(val)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *IpOpt) String() string {
|
|
|
|
return (*o.IP).String()
|
|
|
|
}
|