Created
November 1, 2020 12:06
-
-
Save RicardoLinck/f26d05d74750426715e2018513ecac03 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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