mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 10:43:17 -04:00
K8s remove string ops (#2119)
* plugin/kubernetes: remove bunch a string ops This removes a bunch of appends to where not needed, makes dnsutil.Join take variadic args which removes the need to wrap in a new string slice. Signed-off-by: Miek Gieben <miek@miek.nl> * Fix calls to dnsutil.Join Signed-off-by: Miek Gieben <miek@miek.nl> * Revert these Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
@@ -8,12 +8,10 @@ import (
|
||||
|
||||
// Join joins labels to form a fully qualified domain name. If the last label is
|
||||
// the root label it is ignored. Not other syntax checks are performed.
|
||||
func Join(labels []string) string {
|
||||
func Join(labels ...string) string {
|
||||
ll := len(labels)
|
||||
if labels[ll-1] == "." {
|
||||
s := strings.Join(labels[:ll-1], ".")
|
||||
return dns.Fqdn(s)
|
||||
return strings.Join(labels[:ll-1], ".") + "."
|
||||
}
|
||||
s := strings.Join(labels, ".")
|
||||
return dns.Fqdn(s)
|
||||
return dns.Fqdn(strings.Join(labels, "."))
|
||||
}
|
||||
|
||||
@@ -9,11 +9,12 @@ func TestJoin(t *testing.T) {
|
||||
}{
|
||||
{[]string{"bla", "bliep", "example", "org"}, "bla.bliep.example.org."},
|
||||
{[]string{"example", "."}, "example."},
|
||||
{[]string{"example", "org."}, "example.org."}, // technically we should not be called like this.
|
||||
{[]string{"."}, "."},
|
||||
}
|
||||
|
||||
for i, tc := range tests {
|
||||
if x := Join(tc.in); x != tc.out {
|
||||
if x := Join(tc.in...); x != tc.out {
|
||||
t.Errorf("Test %d, expected %s, got %s", i, tc.out, x)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user