libnetwork/netlabel: remove Key(), Value(), and KeyValue() utils
These were only used in a single location, and in a rather bad way; replace them with strings.Cut() which should be all we need for this. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
9015cb7111
commit
a959487597
3 changed files with 3 additions and 52 deletions
|
@ -406,11 +406,12 @@ func (c *controller) makeDriverConfig(ntype string) map[string]interface{} {
|
|||
|
||||
cfg := map[string]interface{}{}
|
||||
for _, label := range c.cfg.Labels {
|
||||
if !strings.HasPrefix(netlabel.Key(label), netlabel.DriverPrefix+"."+ntype) {
|
||||
key, val, _ := strings.Cut(label, "=")
|
||||
if !strings.HasPrefix(key, netlabel.DriverPrefix+"."+ntype) {
|
||||
continue
|
||||
}
|
||||
|
||||
cfg[netlabel.Key(label)] = netlabel.Value(label)
|
||||
cfg[key] = val
|
||||
}
|
||||
|
||||
drvCfg, ok := c.cfg.DriverCfg[ntype]
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
package netlabel
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
// Prefix constant marks the reserved label space for libnetwork
|
||||
Prefix = "com.docker.network"
|
||||
|
@ -101,21 +97,3 @@ func MakeKVProviderConfig(scope string) string {
|
|||
func MakeKVClient(scope string) string {
|
||||
return DriverPrivatePrefix + scope + "kv_client"
|
||||
}
|
||||
|
||||
// Key extracts the key portion of the label
|
||||
func Key(label string) (key string) {
|
||||
key, _, _ = strings.Cut(label, "=")
|
||||
return key
|
||||
}
|
||||
|
||||
// Value extracts the value portion of the label
|
||||
func Value(label string) (value string) {
|
||||
_, value, _ = strings.Cut(label, "=")
|
||||
return value
|
||||
}
|
||||
|
||||
// KeyValue decomposes the label in the (key,value) pair
|
||||
func KeyValue(label string) (key string, value string) {
|
||||
key, value, _ = strings.Cut(label, "=")
|
||||
return key, value
|
||||
}
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
package netlabel
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var input = []struct {
|
||||
label string
|
||||
key string
|
||||
value string
|
||||
}{
|
||||
{"com.directory.person.name=joe", "com.directory.person.name", "joe"},
|
||||
{"com.directory.person.age=24", "com.directory.person.age", "24"},
|
||||
{"com.directory.person.address=1234 First st.", "com.directory.person.address", "1234 First st."},
|
||||
{"com.directory.person.friends=", "com.directory.person.friends", ""},
|
||||
{"com.directory.person.nickname=o=u=8", "com.directory.person.nickname", "o=u=8"},
|
||||
{"", "", ""},
|
||||
{"com.directory.person.student", "com.directory.person.student", ""},
|
||||
}
|
||||
|
||||
func TestKeyValue(t *testing.T) {
|
||||
for _, i := range input {
|
||||
k, v := KeyValue(i.label)
|
||||
if k != i.key || v != i.value {
|
||||
t.Fatalf("unexpected: %s, %s", k, v)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue