Skip to content

Instantly share code, notes, and snippets.

@RicardoLinck
Created November 1, 2020 12:06
Show Gist options
  • Save RicardoLinck/f26d05d74750426715e2018513ecac03 to your computer and use it in GitHub Desktop.
Save RicardoLinck/f26d05d74750426715e2018513ecac03 to your computer and use it in GitHub Desktop.
// Configuration contain parameters to call the api
type Configuration struct {
baseURL string
apiVersion int
}
// FetchData fetches the data from the api using the configuration
func (c Configuration) FetchData() (Person, error) {
person := Person{}
endpoint, decoderFunc, err := getEndpointAndDecodeFunc(c.apiVersion)
if err != nil {
return person, err
}
response, err := http.DefaultClient.Get(c.baseURL + endpoint)
if err != nil {
return person, err
}
defer response.Body.Close()
return decoderFunc(response.Body)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment