diff --git a/opts/envfile.go b/opts/envfile.go index 1a7284f56c..a1cfbae5e4 100644 --- a/opts/envfile.go +++ b/opts/envfile.go @@ -9,13 +9,13 @@ import ( ) var ( - // EnvironmentVariableRegexp A regexp to validate correct environment variables + // EnvironmentVariableRegexp is a regexp to validate correct environment variables // Environment variables set by the user must have a name consisting solely of // alphabetics, numerics, and underscores - the first of which must not be numeric. EnvironmentVariableRegexp = regexp.MustCompile("^[[:alpha:]_][[:alpha:][:digit:]_]*$") ) -// ParseEnvFile Read in a line delimited file with environment variables enumerated +// ParseEnvFile reads a file with environment variables enumerated by lines func ParseEnvFile(filename string) ([]string, error) { fh, err := os.Open(filename) if err != nil { diff --git a/opts/hosts_unix.go b/opts/hosts_unix.go index a29335e605..611407a9d9 100644 --- a/opts/hosts_unix.go +++ b/opts/hosts_unix.go @@ -4,4 +4,5 @@ package opts import "fmt" +// DefaultHost constant defines the default host string used by docker on other hosts than Windows var DefaultHost = fmt.Sprintf("unix://%s", DefaultUnixSocket) diff --git a/opts/hosts_windows.go b/opts/hosts_windows.go index 55eac2aaca..0b5c8a5b8d 100644 --- a/opts/hosts_windows.go +++ b/opts/hosts_windows.go @@ -4,4 +4,5 @@ package opts import "fmt" +// DefaultHost constant defines the default host string used by docker on Windows var DefaultHost = fmt.Sprintf("tcp://%s:%d", DefaultHTTPHost, DefaultHTTPPort) diff --git a/opts/ip.go b/opts/ip.go index 1268789fb1..d787b56ca6 100644 --- a/opts/ip.go +++ b/opts/ip.go @@ -5,12 +5,14 @@ import ( "net" ) -// IPOpt type that hold an IP +// IPOpt holds an IP. It is used to store values from CLI flags. type IPOpt struct { *net.IP } -// NewIPOpt returns a new IPOpt from a string of an IP. +// NewIPOpt creates a new IPOpt from a reference net.IP and a +// string representation of an IP. If the string is not a valid +// IP it will fallback to the specified reference. func NewIPOpt(ref *net.IP, defaultVal string) *IPOpt { o := &IPOpt{ IP: ref, @@ -20,7 +22,7 @@ func NewIPOpt(ref *net.IP, defaultVal string) *IPOpt { } // 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. +// string is not parsable as an IP address it returns an error. func (o *IPOpt) Set(val string) error { ip := net.ParseIP(val) if ip == nil { @@ -30,7 +32,7 @@ func (o *IPOpt) Set(val string) error { return nil } -// String returns the IP address stored in the IPOpt. If IPOpt is a +// String returns the IP address stored in the IPOpt. If stored IP is a // nil pointer, it returns an empty string. func (o *IPOpt) String() string { if *o.IP == nil { diff --git a/opts/opts.go b/opts/opts.go index aa8d593b7e..392bc49735 100644 --- a/opts/opts.go +++ b/opts/opts.go @@ -27,18 +27,19 @@ var ( DefaultUnixSocket = "/var/run/docker.sock" ) -// ListOpts type that hold a list of values and a validation function. +// ListOpts holds a list of values and a validation function. type ListOpts struct { values *[]string validator ValidatorFctType } -// NewListOpts Create a new ListOpts with the specified validator. +// NewListOpts creates a new ListOpts with the specified validator. func NewListOpts(validator ValidatorFctType) ListOpts { var values []string return *NewListOptsRef(&values, validator) } +// NewListOptsRef creates a new ListOpts with the specified values and validator. func NewListOptsRef(values *[]string, validator ValidatorFctType) *ListOpts { return &ListOpts{ values: values, @@ -64,7 +65,7 @@ func (opts *ListOpts) Set(value string) error { return nil } -// Delete remove the given element from the slice. +// Delete removes the specified element from the slice. func (opts *ListOpts) Delete(key string) { for i, k := range *opts.values { if k == key { @@ -85,13 +86,13 @@ func (opts *ListOpts) GetMap() map[string]struct{} { return ret } -// GetAll returns the values' slice. +// GetAll returns the values of slice. // FIXME: Can we remove this? func (opts *ListOpts) GetAll() []string { return (*opts.values) } -// Get checks the existence of the given key. +// Get checks the existence of the specified key. func (opts *ListOpts) Get(key string) bool { for _, k := range *opts.values { if k == key { @@ -106,7 +107,7 @@ func (opts *ListOpts) Len() int { return len((*opts.values)) } -//MapOpts type that holds a map of values and a validation function. +//MapOpts holds a map of values and a validation function. type MapOpts struct { values map[string]string validator ValidatorFctType @@ -131,6 +132,7 @@ func (opts *MapOpts) Set(value string) error { return nil } +// GetAll returns the values of MapOpts as a map. func (opts *MapOpts) GetAll() map[string]string { return opts.values } @@ -139,6 +141,7 @@ func (opts *MapOpts) String() string { return fmt.Sprintf("%v", map[string]string((opts.values))) } +// NewMapOpts creates a new MapOpts with the specified map of values and a validator. func NewMapOpts(values map[string]string, validator ValidatorFctType) *MapOpts { if values == nil { values = make(map[string]string) @@ -149,13 +152,13 @@ func NewMapOpts(values map[string]string, validator ValidatorFctType) *MapOpts { } } -// ValidatorFctType validator that return a validate string and/or an error +// ValidatorFctType defines a validator function that returns a validated string and/or an error. type ValidatorFctType func(val string) (string, error) -// ValidatorFctListType validator that return a validate list of string and/or an error +// ValidatorFctListType defines a validator function that returns a validated list of string and/or an error type ValidatorFctListType func(val string) ([]string, error) -// ValidateAttach Validates that the specified string is a valid attach option. +// ValidateAttach validates that the specified string is a valid attach option. func ValidateAttach(val string) (string, error) { s := strings.ToLower(val) for _, str := range []string{"stdin", "stdout", "stderr"} { @@ -166,7 +169,7 @@ func ValidateAttach(val string) (string, error) { return val, fmt.Errorf("valid streams are STDIN, STDOUT and STDERR") } -// ValidateLink Validates that the specified string has a valid link format (containerName:alias). +// ValidateLink validates that the specified string has a valid link format (containerName:alias). func ValidateLink(val string) (string, error) { if _, _, err := parsers.ParseLink(val); err != nil { return val, err @@ -194,18 +197,18 @@ func ValidDeviceMode(mode string) bool { return true } -// ValidateDevice Validate a path for devices +// ValidateDevice validates a path for devices // It will make sure 'val' is in the form: // [host-dir:]container-path[:mode] -// It will also validate the device mode. +// It also validates the device mode. func ValidateDevice(val string) (string, error) { return validatePath(val, ValidDeviceMode) } -// ValidatePath Validate a path for volumes +// ValidatePath validates a path for volumes // It will make sure 'val' is in the form: // [host-dir:]container-path[:rw|ro] -// It will also validate the mount mode. +// It also validates the mount mode. func ValidatePath(val string) (string, error) { return validatePath(val, volume.ValidMountMode) } @@ -250,8 +253,8 @@ func validatePath(val string, validator func(string) bool) (string, error) { return val, nil } -// ValidateEnv Validate an environment variable and returns it -// It will use EnvironmentVariableRegexp to ensure the name of the environment variable is valid. +// ValidateEnv validates an environment variable and returns it. +// It uses EnvironmentVariableRegexp to ensure the name of the environment variable is valid. // If no value is specified, it returns the current value using os.Getenv. func ValidateEnv(val string) (string, error) { arr := strings.Split(val, "=") @@ -267,7 +270,7 @@ func ValidateEnv(val string) (string, error) { return fmt.Sprintf("%s=%s", val, os.Getenv(val)), nil } -// ValidateIPAddress Validates an Ip address +// ValidateIPAddress validates an Ip address. func ValidateIPAddress(val string) (string, error) { var ip = net.ParseIP(strings.TrimSpace(val)) if ip != nil { @@ -276,7 +279,7 @@ func ValidateIPAddress(val string) (string, error) { return "", fmt.Errorf("%s is not an ip address", val) } -// ValidateMACAddress Validates a MAC address +// ValidateMACAddress validates a MAC address. func ValidateMACAddress(val string) (string, error) { _, err := net.ParseMAC(strings.TrimSpace(val)) if err != nil { @@ -285,8 +288,8 @@ func ValidateMACAddress(val string) (string, error) { return val, nil } -// ValidateDNSSearch Validates domain for resolvconf search configuration. -// A zero length domain is represented by . +// ValidateDNSSearch validates domain for resolvconf search configuration. +// A zero length domain is represented by a dot (.). func ValidateDNSSearch(val string) (string, error) { if val = strings.Trim(val, " "); val == "." { return val, nil @@ -305,8 +308,8 @@ func validateDomain(val string) (string, error) { return "", fmt.Errorf("%s is not a valid domain", val) } -// ValidateExtraHost Validate that the given string is a valid extrahost and returns it -// ExtraHost are in the form of name:ip where the ip has to be a valid ip (ipv4 or ipv6) +// ValidateExtraHost validates that the specified string is a valid extrahost and returns it. +// ExtraHost are in the form of name:ip where the ip has to be a valid ip (ipv4 or ipv6). func ValidateExtraHost(val string) (string, error) { // allow for IPv6 addresses in extra hosts by only splitting on first ":" arr := strings.SplitN(val, ":", 2) @@ -319,8 +322,8 @@ func ValidateExtraHost(val string) (string, error) { return val, nil } -// ValidateLabel Validate that the given string is a valid label, and returns it -// Labels are in the form on key=value +// ValidateLabel validates that the specified string is a valid label, and returns it. +// Labels are in the form on key=value. func ValidateLabel(val string) (string, error) { if strings.Count(val, "=") < 1 { return "", fmt.Errorf("bad attribute format: %s", val) @@ -328,7 +331,7 @@ func ValidateLabel(val string) (string, error) { return val, nil } -// ValidateHost Validate that the given string is a valid host and returns it +// ValidateHost validates that the specified string is a valid host and returns it. func ValidateHost(val string) (string, error) { host, err := parsers.ParseHost(DefaultHTTPHost, DefaultUnixSocket, val) if err != nil {