-
Notifications
You must be signed in to change notification settings - Fork 949
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
45 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,25 @@ | ||
package opts | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// ParseLabels parses the labels params of container. | ||
func ParseLabels(labels []string) (map[string]string, error) { | ||
func ParseLabels(labels []string) map[string]string { | ||
results := make(map[string]string) | ||
for _, label := range labels { | ||
fields, err := parseLabel(label) | ||
if err != nil { | ||
return nil, err | ||
} | ||
fields := parseLabel(label) | ||
k, v := fields[0], fields[1] | ||
results[k] = v | ||
} | ||
return results, nil | ||
return results | ||
} | ||
|
||
func parseLabel(label string) ([]string, error) { | ||
func parseLabel(label string) []string { | ||
fields := strings.SplitN(label, "=", 2) | ||
if len(fields) != 2 { | ||
return nil, fmt.Errorf("invalid label %s: label must be in format of key=value", label) | ||
// Only input key without value | ||
if len(fields) == 1 { | ||
fields = append(fields, "") | ||
} | ||
return fields, nil | ||
return fields | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters