plugin: use strings.Cut()

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-11-01 12:47:12 +01:00
parent 01365cbd74
commit bffb35612c
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 7 additions and 10 deletions

View file

@ -1,7 +1,6 @@
package plugin // import "github.com/docker/docker/plugin"
import (
"fmt"
"strings"
"sync"
@ -56,15 +55,13 @@ func WithEnv(env []string) CreateOpt {
}
}
for _, line := range env {
if pair := strings.SplitN(line, "=", 2); len(pair) > 1 {
effectiveEnv[pair[0]] = pair[1]
if k, v, ok := strings.Cut(line, "="); ok {
effectiveEnv[k] = v
}
}
p.PluginObj.Settings.Env = make([]string, len(effectiveEnv))
i := 0
p.PluginObj.Settings.Env = make([]string, 0, len(effectiveEnv))
for key, value := range effectiveEnv {
p.PluginObj.Settings.Env[i] = fmt.Sprintf("%s=%s", key, value)
i++
p.PluginObj.Settings.Env = append(p.PluginObj.Settings.Env, key+"="+value)
}
}
}

View file

@ -92,11 +92,11 @@ func (set *settable) isSettable(allowedSettableFields []string, settable []strin
func updateSettingsEnv(env *[]string, set *settable) {
for i, e := range *env {
if parts := strings.SplitN(e, "=", 2); parts[0] == set.name {
(*env)[i] = fmt.Sprintf("%s=%s", set.name, set.value)
if name, _, _ := strings.Cut(e, "="); name == set.name {
(*env)[i] = set.name + "=" + set.value
return
}
}
*env = append(*env, fmt.Sprintf("%s=%s", set.name, set.value))
*env = append(*env, set.name+"="+set.value)
}