Signed-off-by: Sevki Hasirci <s@sevki.org>
| ... | ... |
@@ -5,20 +5,23 @@ import ( |
| 5 | 5 |
"net" |
| 6 | 6 |
) |
| 7 | 7 |
|
| 8 |
-// IpOpt type that hold an IP |
|
| 9 |
-type IpOpt struct {
|
|
| 8 |
+// IPOpt type that hold an IP |
|
| 9 |
+type IPOpt struct {
|
|
| 10 | 10 |
*net.IP |
| 11 | 11 |
} |
| 12 | 12 |
|
| 13 |
-func NewIpOpt(ref *net.IP, defaultVal string) *IpOpt {
|
|
| 14 |
- o := &IpOpt{
|
|
| 13 |
+// NewIPOpt returns a new IPOpt from a string of an IP. |
|
| 14 |
+func NewIPOpt(ref *net.IP, defaultVal string) *IPOpt {
|
|
| 15 |
+ o := &IPOpt{
|
|
| 15 | 16 |
IP: ref, |
| 16 | 17 |
} |
| 17 | 18 |
o.Set(defaultVal) |
| 18 | 19 |
return o |
| 19 | 20 |
} |
| 20 | 21 |
|
| 21 |
-func (o *IpOpt) Set(val string) error {
|
|
| 22 |
+// Set sets an IPv4 or IPv6 address from a given string. If the given |
|
| 23 |
+// string is not parsable as an IP address it will return an error. |
|
| 24 |
+func (o *IPOpt) Set(val string) error {
|
|
| 22 | 25 |
ip := net.ParseIP(val) |
| 23 | 26 |
if ip == nil {
|
| 24 | 27 |
return fmt.Errorf("%s is not an ip address", val)
|
| ... | ... |
@@ -27,7 +30,9 @@ func (o *IpOpt) Set(val string) error {
|
| 27 | 27 |
return nil |
| 28 | 28 |
} |
| 29 | 29 |
|
| 30 |
-func (o *IpOpt) String() string {
|
|
| 30 |
+// String returns the IP address stored in the IPOpt. If IPOpt is a |
|
| 31 |
+// nil pointer, it returns an empty string. |
|
| 32 |
+func (o *IPOpt) String() string {
|
|
| 31 | 33 |
if *o.IP == nil {
|
| 32 | 34 |
return "" |
| 33 | 35 |
} |
| ... | ... |
@@ -45,9 +45,9 @@ func TestIpOptSetInvalidVal(t *testing.T) {
|
| 45 | 45 |
ip := net.IPv4(127, 0, 0, 1) |
| 46 | 46 |
ipOpt := &IpOpt{IP: &ip}
|
| 47 | 47 |
|
| 48 |
- invalidIp := "invalid ip" |
|
| 48 |
+ invalidIP := "invalid ip" |
|
| 49 | 49 |
expectedError := "invalid ip is not an ip address" |
| 50 |
- err := ipOpt.Set(invalidIp) |
|
| 50 |
+ err := ipOpt.Set(invalidIP) |
|
| 51 | 51 |
if err == nil || err.Error() != expectedError {
|
| 52 | 52 |
t.Fatalf("Expected an Error with [%v], got [%v]", expectedError, err.Error())
|
| 53 | 53 |
} |
| ... | ... |
@@ -6,10 +6,12 @@ import ( |
| 6 | 6 |
"github.com/docker/docker/pkg/ulimit" |
| 7 | 7 |
) |
| 8 | 8 |
|
| 9 |
+// UlimitOpt defines a map of Ulimits |
|
| 9 | 10 |
type UlimitOpt struct {
|
| 10 | 11 |
values *map[string]*ulimit.Ulimit |
| 11 | 12 |
} |
| 12 | 13 |
|
| 14 |
+// NewUlimitOpt creates a new UlimitOpt |
|
| 13 | 15 |
func NewUlimitOpt(ref *map[string]*ulimit.Ulimit) *UlimitOpt {
|
| 14 | 16 |
if ref == nil {
|
| 15 | 17 |
ref = &map[string]*ulimit.Ulimit{}
|
| ... | ... |
@@ -17,6 +19,7 @@ func NewUlimitOpt(ref *map[string]*ulimit.Ulimit) *UlimitOpt {
|
| 17 | 17 |
return &UlimitOpt{ref}
|
| 18 | 18 |
} |
| 19 | 19 |
|
| 20 |
+// Set validates a Ulimit and sets its name as a key in UlimitOpt |
|
| 20 | 21 |
func (o *UlimitOpt) Set(val string) error {
|
| 21 | 22 |
l, err := ulimit.Parse(val) |
| 22 | 23 |
if err != nil {
|
| ... | ... |
@@ -28,6 +31,7 @@ func (o *UlimitOpt) Set(val string) error {
|
| 28 | 28 |
return nil |
| 29 | 29 |
} |
| 30 | 30 |
|
| 31 |
+// String returns Ulimit values as a string. |
|
| 31 | 32 |
func (o *UlimitOpt) String() string {
|
| 32 | 33 |
var out []string |
| 33 | 34 |
for _, v := range *o.values {
|
| ... | ... |
@@ -37,6 +41,7 @@ func (o *UlimitOpt) String() string {
|
| 37 | 37 |
return fmt.Sprintf("%v", out)
|
| 38 | 38 |
} |
| 39 | 39 |
|
| 40 |
+// GetList returns a slice of pointers to Ulimits. |
|
| 40 | 41 |
func (o *UlimitOpt) GetList() []*ulimit.Ulimit {
|
| 41 | 42 |
var ulimits []*ulimit.Ulimit |
| 42 | 43 |
for _, v := range *o.values {
|