Skip to content

Commit

Permalink
Opts lint issues, ip and ulimit
Browse files Browse the repository at this point in the history
Signed-off-by: Sevki Hasirci <[email protected]>
  • Loading branch information
sevki authored and vdemeester committed Aug 27, 2015
1 parent 4579d5a commit 6eb03c5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
17 changes: 11 additions & 6 deletions opts/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 ""
}
Expand Down
4 changes: 2 additions & 2 deletions opts/ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
5 changes: 5 additions & 0 deletions opts/ulimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ 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{}
}
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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 6eb03c5

Please sign in to comment.