From 01bd02e8c57bf21756d772be0b92a31db32edf7a Mon Sep 17 00:00:00 2001 From: "fiatjaf@spooner" Date: Fri, 26 Feb 2016 16:29:49 -0500 Subject: [PATCH] remove unnecessary pointers. Closes https://github.com/VojtechVitek/go-trello/issues/21 --- checklist.go | 16 ++++++++-------- client.go | 8 ++++---- tests/client_test.go | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/checklist.go b/checklist.go index 41c5e3a..c85a6c8 100644 --- a/checklist.go +++ b/checklist.go @@ -64,26 +64,26 @@ func (c *Checklist) Delete() error { // name must have a length 1 <= length <= 16384 // pos can take the values 'top', 'bottom', or a positive integer // https://developers.trello.com/advanced-reference/checklist#post-1-checklists-idchecklist-checkitems -func (c *Checklist) AddItem(name string, pos *string, checked *bool) (*ChecklistItem, error) { +func (c *Checklist) AddItem(name string, pos string, checked bool) (*ChecklistItem, error) { payload := url.Values{} if len(name) < 1 || len(name) > 16384 { return nil, fmt.Errorf("Checklist item name %q has invalid length. 1 <= length <= 16384", name) } payload.Set("name", name) - if pos != nil { - if *pos != "top" && *pos != "bottom" { - i, err := strconv.Atoi(*pos) + if pos != "" { + if pos != "top" && pos != "bottom" { + i, err := strconv.Atoi(pos) if err != nil { return nil, err } if i < 1 { - return nil, fmt.Errorf("Checklist item position %q is invalid. Only 'top', 'bottom', or a positive integer", *pos) + return nil, fmt.Errorf("Checklist item position %q is invalid. Only 'top', 'bottom', or a positive integer", pos) } } - payload.Set("pos", *pos) + payload.Set("pos", pos) } - if checked != nil { - payload.Set("checked", strconv.FormatBool(*checked)) + if checked { + payload.Set("checked", strconv.FormatBool(checked)) } body, err := c.client.Post("/checklist/"+c.Id+"/checkItems", payload) if err != nil { diff --git a/client.go b/client.go index 2f7d03d..316b2cc 100644 --- a/client.go +++ b/client.go @@ -78,7 +78,7 @@ func (c *Client) Delete(resource string) ([]byte, error) { type bearerRoundTripper struct { Delegate http.RoundTripper key string - token *string + token string } func (b *bearerRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { @@ -87,7 +87,7 @@ func (b *bearerRoundTripper) RoundTrip(req *http.Request) (*http.Response, error } values := req.URL.Query() values.Add("key", b.key) - values.Add("token", *b.token) + values.Add("token", b.token) req.URL.RawQuery = values.Encode() return b.Delegate.RoundTrip(req) } @@ -98,7 +98,7 @@ func (b *bearerRoundTripper) RoundTrip(req *http.Request) (*http.Response, error // See https://trello.com/app-key to get your applicationKey // See https://trello.com/1/connect?key=MYKEYFROMABOVE&name=MYAPPNAME&response_type=token&scope=read,write&expiration=1d // to get a read/write token good for 1 day -func NewBearerTokenTransport(applicationKey string, token *string) *bearerRoundTripper { +func NewBearerTokenTransport(applicationKey string, token string) *bearerRoundTripper { return &bearerRoundTripper{ key: applicationKey, token: token, @@ -120,7 +120,7 @@ func NewCustomClient(client *http.Client) (*Client, error) { // NewAuthClient will create a trello client which allows authentication. It uses // NewBearerTokenTransport to create an http.Client which can be used as a trello // client. -func NewAuthClient(applicationKey string, token *string) (*Client, error) { +func NewAuthClient(applicationKey string, token string) (*Client, error) { rr := NewBearerTokenTransport(applicationKey, token) client := &http.Client{ Transport: rr, diff --git a/tests/client_test.go b/tests/client_test.go index 858afd4..2156821 100644 --- a/tests/client_test.go +++ b/tests/client_test.go @@ -38,7 +38,7 @@ func TestManyThings(t *testing.T) { g.It("should create a client", func() { key := os.Getenv("API_KEY") token := os.Getenv("API_TOKEN") - Client, err = trello.NewAuthClient(key, &token) + Client, err = trello.NewAuthClient(key, token) Expect(err).To(BeNil()) })