github.com/ralexstokes/docker@v1.6.2/opts/ip.go (about)

     1  package opts
     2  
     3  import (
     4  	"fmt"
     5  	"net"
     6  )
     7  
     8  type IpOpt struct {
     9  	*net.IP
    10  }
    11  
    12  func NewIpOpt(ref *net.IP, defaultVal string) *IpOpt {
    13  	o := &IpOpt{
    14  		IP: ref,
    15  	}
    16  	o.Set(defaultVal)
    17  	return o
    18  }
    19  
    20  func (o *IpOpt) Set(val string) error {
    21  	ip := net.ParseIP(val)
    22  	if ip == nil {
    23  		return fmt.Errorf("%s is not an ip address", val)
    24  	}
    25  	(*o.IP) = net.ParseIP(val)
    26  	return nil
    27  }
    28  
    29  func (o *IpOpt) String() string {
    30  	return (*o.IP).String()
    31  }