Merge pull request #404 from RainbowMango/pr_fix_Stringer
Change the receiver of Stringer interface implementation
This commit is contained in:
commit
552e75a2b9
|
@ -68,7 +68,7 @@ func (c *Components) FullRepository() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns the full name of the image, including repository and tag(or digest).
|
// String returns the full name of the image, including repository and tag(or digest).
|
||||||
func (c *Components) String() string {
|
func (c Components) String() string {
|
||||||
if c.tag != "" {
|
if c.tag != "" {
|
||||||
return c.FullRepository() + ":" + c.tag
|
return c.FullRepository() + ":" + c.tag
|
||||||
} else if c.digest != "" {
|
} else if c.digest != "" {
|
||||||
|
|
|
@ -189,3 +189,25 @@ func ExampleComponents_SetTagOrDigest() {
|
||||||
// gcr.io/kube-apiserver@sha256:50d858e0985ecc7f60418aaf0cc5ab587f42c2570a884095a9e8ccacd0f6545c
|
// gcr.io/kube-apiserver@sha256:50d858e0985ecc7f60418aaf0cc5ab587f42c2570a884095a9e8ccacd0f6545c
|
||||||
// gcr.io/kube-apiserver
|
// gcr.io/kube-apiserver
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExampleComponents_String() {
|
||||||
|
key := Components{
|
||||||
|
hostname: "fictional.registry.example",
|
||||||
|
repository: "karmada-scheduler",
|
||||||
|
tag: "v1.0.0",
|
||||||
|
}
|
||||||
|
pKey := &key
|
||||||
|
fmt.Printf("%s\n", key)
|
||||||
|
fmt.Printf("%v\n", key)
|
||||||
|
fmt.Printf("%s\n", key.String())
|
||||||
|
fmt.Printf("%s\n", pKey)
|
||||||
|
fmt.Printf("%v\n", pKey)
|
||||||
|
fmt.Printf("%s\n", pKey.String())
|
||||||
|
// Output:
|
||||||
|
// fictional.registry.example/karmada-scheduler:v1.0.0
|
||||||
|
// fictional.registry.example/karmada-scheduler:v1.0.0
|
||||||
|
// fictional.registry.example/karmada-scheduler:v1.0.0
|
||||||
|
// fictional.registry.example/karmada-scheduler:v1.0.0
|
||||||
|
// fictional.registry.example/karmada-scheduler:v1.0.0
|
||||||
|
// fictional.registry.example/karmada-scheduler:v1.0.0
|
||||||
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ type ClusterWideKey struct {
|
||||||
|
|
||||||
// String returns the key's printable info with format:
|
// String returns the key's printable info with format:
|
||||||
// "<GroupVersion>, kind=<Kind>, <NamespaceKey>"
|
// "<GroupVersion>, kind=<Kind>, <NamespaceKey>"
|
||||||
func (k *ClusterWideKey) String() string {
|
func (k ClusterWideKey) String() string {
|
||||||
return fmt.Sprintf("%s, kind=%s, %s", k.GroupVersion().String(), k.Kind, k.NamespaceKey())
|
return fmt.Sprintf("%s, kind=%s, %s", k.GroupVersion().String(), k.Kind, k.NamespaceKey())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ type FederatedKey struct {
|
||||||
|
|
||||||
// String returns the key's printable info with format:
|
// String returns the key's printable info with format:
|
||||||
// "cluster=<Cluster>, <GroupVersion>, kind=<Kind>, <NamespaceKey>"
|
// "cluster=<Cluster>, <GroupVersion>, kind=<Kind>, <NamespaceKey>"
|
||||||
func (f *FederatedKey) String() string {
|
func (f FederatedKey) String() string {
|
||||||
return fmt.Sprintf("cluster=%s, %s, kind=%s, %s", f.Cluster, f.GroupVersion().String(), f.Kind, f.NamespaceKey())
|
return fmt.Sprintf("cluster=%s, %s, kind=%s, %s", f.Cluster, f.GroupVersion().String(), f.Kind, f.NamespaceKey())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package keys
|
package keys
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
|
@ -186,3 +187,53 @@ func TestFederatedKeyFunc(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExampleClusterWideKey_String() {
|
||||||
|
key := ClusterWideKey{
|
||||||
|
Group: "apps",
|
||||||
|
Version: "v1",
|
||||||
|
Kind: "Namespace",
|
||||||
|
Namespace: "default",
|
||||||
|
Name: "foo",
|
||||||
|
}
|
||||||
|
pKey := &key
|
||||||
|
fmt.Printf("%s\n", key)
|
||||||
|
fmt.Printf("%v\n", key)
|
||||||
|
fmt.Printf("%s\n", key.String())
|
||||||
|
fmt.Printf("%s\n", pKey)
|
||||||
|
fmt.Printf("%v\n", pKey)
|
||||||
|
fmt.Printf("%s\n", pKey.String())
|
||||||
|
// Output:
|
||||||
|
// apps/v1, kind=Namespace, default/foo
|
||||||
|
// apps/v1, kind=Namespace, default/foo
|
||||||
|
// apps/v1, kind=Namespace, default/foo
|
||||||
|
// apps/v1, kind=Namespace, default/foo
|
||||||
|
// apps/v1, kind=Namespace, default/foo
|
||||||
|
// apps/v1, kind=Namespace, default/foo
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExampleFederatedKey_String() {
|
||||||
|
key := FederatedKey{
|
||||||
|
Cluster: "karamda",
|
||||||
|
ClusterWideKey: ClusterWideKey{
|
||||||
|
Group: "apps",
|
||||||
|
Version: "v1",
|
||||||
|
Kind: "Namespace",
|
||||||
|
Namespace: "default",
|
||||||
|
Name: "foo"},
|
||||||
|
}
|
||||||
|
pKey := &key
|
||||||
|
fmt.Printf("%s\n", key)
|
||||||
|
fmt.Printf("%v\n", key)
|
||||||
|
fmt.Printf("%s\n", key.String())
|
||||||
|
fmt.Printf("%s\n", pKey)
|
||||||
|
fmt.Printf("%v\n", pKey)
|
||||||
|
fmt.Printf("%s\n", pKey.String())
|
||||||
|
// Output:
|
||||||
|
// cluster=karamda, apps/v1, kind=Namespace, default/foo
|
||||||
|
// cluster=karamda, apps/v1, kind=Namespace, default/foo
|
||||||
|
// cluster=karamda, apps/v1, kind=Namespace, default/foo
|
||||||
|
// cluster=karamda, apps/v1, kind=Namespace, default/foo
|
||||||
|
// cluster=karamda, apps/v1, kind=Namespace, default/foo
|
||||||
|
// cluster=karamda, apps/v1, kind=Namespace, default/foo
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue