daemon/cluster: use strings.Cut()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
298d3aa8b8
commit
c545473920
2 changed files with 8 additions and 8 deletions
|
@ -637,18 +637,18 @@ func parsePortMap(portMap nat.PortMap) ([]*api.PortConfig, error) {
|
|||
exposedPorts := make([]*api.PortConfig, 0, len(portMap))
|
||||
|
||||
for portProtocol, mapping := range portMap {
|
||||
parts := strings.SplitN(string(portProtocol), "/", 2)
|
||||
if len(parts) != 2 {
|
||||
p, proto, ok := strings.Cut(string(portProtocol), "/")
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid port mapping: %s", portProtocol)
|
||||
}
|
||||
|
||||
port, err := strconv.ParseUint(parts[0], 10, 16)
|
||||
port, err := strconv.ParseUint(p, 10, 16)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var protocol api.PortConfig_Protocol
|
||||
switch strings.ToLower(parts[1]) {
|
||||
switch strings.ToLower(proto) {
|
||||
case "tcp":
|
||||
protocol = api.ProtocolTCP
|
||||
case "udp":
|
||||
|
@ -656,7 +656,7 @@ func parsePortMap(portMap nat.PortMap) ([]*api.PortConfig, error) {
|
|||
case "sctp":
|
||||
protocol = api.ProtocolSCTP
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid protocol: %s", parts[1])
|
||||
return nil, fmt.Errorf("invalid protocol: %s", proto)
|
||||
}
|
||||
|
||||
for _, binding := range mapping {
|
||||
|
|
|
@ -114,11 +114,11 @@ func (e *executor) Describe(ctx context.Context) (*api.NodeDescription, error) {
|
|||
// parse []string labels into a map[string]string
|
||||
labels := map[string]string{}
|
||||
for _, l := range info.Labels {
|
||||
stringSlice := strings.SplitN(l, "=", 2)
|
||||
k, v, ok := strings.Cut(l, "=")
|
||||
// this will take the last value in the list for a given key
|
||||
// ideally, one shouldn't assign multiple values to the same key
|
||||
if len(stringSlice) > 1 {
|
||||
labels[stringSlice[0]] = stringSlice[1]
|
||||
if ok {
|
||||
labels[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue