1

I'm a Ruby on Rails developer and am now venturing into Go for doing some podio.com API calls. Everything went smoothly so far but I bumped into a small and stupid problem for which I find no answer on the mighty stackoverflow (probably because I don't know what to search for).

A bit of context: Our rails app is already handling all the podio oAuth server-flow we have all the necessary client information (auth_token, refresh_token, ...) and do not need to request that information again.

Instead of doing

 podio.AuthWithAuthCode(clientId, clientSecret, authCode, redirectUri)

I wish to directly create a client object like so

// json data coming from rails
json_auth_token := "{\"access_token\":\"...\",\"refresh_token\":\"...\",\"token_type\":\"\",\"expires_in\":28800,\"transfer_token\":\"\"}"

// creating a AuthToken object
authToken := podio.AuthToken{}
json.Unmarshal([]byte(json_auth_token), &authToken)

// so far so good, but when doing
client := podio.NewClient(authToken)

I get the error

cannot use authToken (type podio.AuthToken) as type *podio.AuthToken in argument to podio.NewClient

Can somebody help me with this? It is not necessarily Podio related. More go related

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
pjmuller
  • 79
  • 8

1 Answers1

2

Currently the type of the variable authToken is podio.AuthToken, i.e. not a pointer, but simply a struct. The function podio.NewClient expects an argument of type *podio.AuthToken (pointer to podio.AuthToken), which is why you're getting a compiler error. The simplest way to fix this would be to simply deference authToken like so:

client := podio.NewClient(&authToken)

Alternatively you can change the type of authToken to *podio.AuthToken:

authToken := &podio.AuthToken{}
json.Unmarshal([]byte(json_auth_token), authToken)
client := podio.NewClient(authToken)

Slightly unrelated (and maybe you omitted this for brevity), but you probably want to check the error returned from json.Unmarshal:

err := json.Unmarshal([]byte(json_auth_token), authToken)
if err != nil {
  // handle error
}
cuvius
  • 383
  • 1
  • 4
  • Works like a charm! an ampersand almost made me crazy. Thanks for the super quick reply Andreas. Appreciate it! – pjmuller Jul 01 '16 at 12:22
  • And indeed, I'm doing an error catching when parsing the json. But did not post it to keep the example code simpler. – pjmuller Jul 01 '16 at 12:23