From 496cfd795e7f55ce0a62587384a1aa14d7ef4bbe Mon Sep 17 00:00:00 2001 From: hayashiki Date: Sun, 4 Oct 2020 13:23:10 +0900 Subject: [PATCH] Refine client def --- docbase.go | 24 ++++-------------------- docbase_test.go | 3 ++- version.go | 2 +- 3 files changed, 7 insertions(+), 22 deletions(-) diff --git a/docbase.go b/docbase.go index d4e7580..2a489b4 100644 --- a/docbase.go +++ b/docbase.go @@ -3,7 +3,6 @@ package docbase import ( "bytes" "encoding/json" - "errors" "fmt" "io/ioutil" "log" @@ -50,7 +49,7 @@ type Client struct { Attachments AttachmentService } -// Response is http response wrapper for Dobase +// Response is http response wrapper for DocBase type Response struct { *http.Response Rate @@ -64,7 +63,7 @@ func newResponse(r *http.Response) *Response { } // NewClient returns client API -func NewClient(httpClient *http.Client, team, token string, opts ...Option) *Client { +func NewClient(httpClient *http.Client, team, token string) *Client { if httpClient == nil { httpClient = http.DefaultClient } @@ -79,14 +78,7 @@ func NewClient(httpClient *http.Client, team, token string, opts ...Option) *Cli AccessToken: token, Team: team, Client: httpClient, - } - - for _, opt := range opts { - opt(cli) - } - - if cli.BaseURL == nil { - cli.BaseURL = baseURL + BaseURL: baseURL, } cli.Posts = &postService{cli} @@ -100,14 +92,6 @@ func NewClient(httpClient *http.Client, team, token string, opts ...Option) *Cli return cli } -type Option func(client *Client) - -func OptionDocBaseURL(url *url.URL) Option { - return func(client *Client) { - client.BaseURL = url - } -} - // NewRequest creates a API request with HTTP method, endpoint path and payload func (c *Client) NewRequest(method, path string, body interface{}) (*http.Request, error) { @@ -203,7 +187,7 @@ func CheckResponse(r *http.Response) error { if err == nil && data != nil { err = json.Unmarshal(data, errorResponse) if err != nil { - errorResponse.err = errors.New("Not JSON") + errorResponse.err = fmt.Errorf("not json structure") } } switch r.StatusCode { diff --git a/docbase_test.go b/docbase_test.go index b0a462d..a3de4fb 100644 --- a/docbase_test.go +++ b/docbase_test.go @@ -21,7 +21,8 @@ func setup() { server = httptest.NewServer(mux) url, _ := url.Parse(server.URL) - client = NewClient(nil, "dummyTeam", "dummyToken", OptionDocBaseURL(url)) + client = NewClient(nil, "dummyTeam", "dummyToken") + client.BaseURL = url } func teardown() { diff --git a/version.go b/version.go index 0934657..9af088f 100644 --- a/version.go +++ b/version.go @@ -1,6 +1,6 @@ package docbase const ( - version = "1.0.1" + version = "1.0.2" revision = "HEAD" )