From 409920de5cdf308a2c96edbc287f7fead0b8ccb9 Mon Sep 17 00:00:00 2001 From: Sevki Hasirci Date: Tue, 21 Jul 2015 19:15:36 +0300 Subject: [PATCH] Opts lint issues, ip and ulimit Signed-off-by: Sevki Hasirci --- opts/ip.go | 17 +++++++++++------ opts/ip_test.go | 4 ++-- opts/ulimit.go | 5 +++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/opts/ip.go b/opts/ip.go index b1f9587555..1268789fb1 100644 --- a/opts/ip.go +++ b/opts/ip.go @@ -5,20 +5,23 @@ import ( "net" ) -// IpOpt type that hold an IP -type IpOpt struct { +// IPOpt type that hold an IP +type IPOpt struct { *net.IP } -func NewIpOpt(ref *net.IP, defaultVal string) *IpOpt { - o := &IpOpt{ +// NewIPOpt returns a new IPOpt from a string of an 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 { +// Set sets an IPv4 or IPv6 address from a given string. If the given +// string is not parsable as an IP address it will return an error. +func (o *IPOpt) Set(val string) error { ip := net.ParseIP(val) if ip == nil { return fmt.Errorf("%s is not an ip address", val) @@ -27,7 +30,9 @@ func (o *IpOpt) Set(val string) error { return nil } -func (o *IpOpt) String() string { +// String returns the IP address stored in the IPOpt. If IPOpt is a +// nil pointer, it returns an empty string. +func (o *IPOpt) String() string { if *o.IP == nil { return "" } diff --git a/opts/ip_test.go b/opts/ip_test.go index b6b526a578..0bbee76169 100644 --- a/opts/ip_test.go +++ b/opts/ip_test.go @@ -45,9 +45,9 @@ func TestIpOptSetInvalidVal(t *testing.T) { ip := net.IPv4(127, 0, 0, 1) ipOpt := &IpOpt{IP: &ip} - invalidIp := "invalid ip" + invalidIP := "invalid ip" expectedError := "invalid ip is not an ip address" - err := ipOpt.Set(invalidIp) + err := ipOpt.Set(invalidIP) if err == nil || err.Error() != expectedError { t.Fatalf("Expected an Error with [%v], got [%v]", expectedError, err.Error()) } diff --git a/opts/ulimit.go b/opts/ulimit.go index f8d34365f5..b41f475bd5 100644 --- a/opts/ulimit.go +++ b/opts/ulimit.go @@ -6,10 +6,12 @@ import ( "github.com/docker/docker/pkg/ulimit" ) +// UlimitOpt defines a map of Ulimits type UlimitOpt struct { values *map[string]*ulimit.Ulimit } +// NewUlimitOpt creates a new UlimitOpt func NewUlimitOpt(ref *map[string]*ulimit.Ulimit) *UlimitOpt { if ref == nil { ref = &map[string]*ulimit.Ulimit{} @@ -17,6 +19,7 @@ func NewUlimitOpt(ref *map[string]*ulimit.Ulimit) *UlimitOpt { return &UlimitOpt{ref} } +// Set validates a Ulimit and sets its name as a key in UlimitOpt func (o *UlimitOpt) Set(val string) error { l, err := ulimit.Parse(val) if err != nil { @@ -28,6 +31,7 @@ func (o *UlimitOpt) Set(val string) error { return nil } +// String returns Ulimit values as a string. func (o *UlimitOpt) String() string { var out []string for _, v := range *o.values { @@ -37,6 +41,7 @@ func (o *UlimitOpt) String() string { return fmt.Sprintf("%v", out) } +// GetList returns a slice of pointers to Ulimits. func (o *UlimitOpt) GetList() []*ulimit.Ulimit { var ulimits []*ulimit.Ulimit for _, v := range *o.values {