diff --git a/client.go b/client.go index 86ace96..3ecf86f 100644 --- a/client.go +++ b/client.go @@ -172,6 +172,13 @@ func (c *Client) String() string { return core.Concat("forge.Client{baseURL=", strconv.Quote(c.baseURL), ", token=", tokenState, ", userAgent=", strconv.Quote(c.userAgent), "}") } +// GoString returns a safe Go-syntax summary of the client configuration. +// +// Usage: +// +// s := fmt.Sprintf("%#v", client) +func (c *Client) GoString() string { return c.String() } + // HasToken reports whether the client was configured with an API token. // // Usage: diff --git a/client_test.go b/client_test.go index 79cd19a..6267101 100644 --- a/client_test.go +++ b/client_test.go @@ -236,6 +236,9 @@ func TestClient_String_Good(t *testing.T) { if got := c.String(); got != want { t.Fatalf("got String()=%q, want %q", got, want) } + if got := fmt.Sprintf("%#v", c); got != want { + t.Fatalf("got GoString=%q, want %q", got, want) + } } func TestAPIError_Error_Good(t *testing.T) { diff --git a/forge.go b/forge.go index 5d0ce5c..fab6e2e 100644 --- a/forge.go +++ b/forge.go @@ -119,3 +119,10 @@ func (f *Forge) HasToken() bool { return f.client.HasToken() } func (f *Forge) String() string { return "forge.Forge{" + f.client.String() + "}" } + +// GoString returns a safe Go-syntax summary of the Forge client. +// +// Usage: +// +// s := fmt.Sprintf("%#v", f) +func (f *Forge) GoString() string { return f.String() } diff --git a/forge_test.go b/forge_test.go index 701a36b..bec674d 100644 --- a/forge_test.go +++ b/forge_test.go @@ -92,6 +92,9 @@ func TestForge_String_Good(t *testing.T) { if got := f.String(); got != want { t.Fatalf("got String()=%q, want %q", got, want) } + if got := fmt.Sprintf("%#v", f); got != want { + t.Fatalf("got GoString=%q, want %q", got, want) + } } func TestRepoService_ListOrgRepos_Good(t *testing.T) {