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