Skip to content

Instantly share code, notes, and snippets.

@koral--
Created October 16, 2018 15:09
Show Gist options
  • Save koral--/05a27643c113cea1b419775417132078 to your computer and use it in GitHub Desktop.
Save koral--/05a27643c113cea1b419775417132078 to your computer and use it in GitHub Desktop.
Chuck Norris jokes Bitrise step URL building
func buildJokeRequest(config Config) (*http.Request, error) {
jokeURL, err := buildJokeURL(config)
if err != nil {
return nil, err
}
request, err := http.NewRequest("GET", jokeURL.String(), nil)
if err != nil {
return nil, err
}
request.Header.Set("Accept", "text/plain")
return request, nil
}
func buildJokeURL(config Config) (*url.URL, error) {
jokeURL, err := url.Parse(config.APIBaseURL)
if err != nil {
return nil, err
}
jokeURL.Path = "/jokes/random"
if len(config.Category) > 0 {
query := jokeURL.Query()
query.Set("category", config.Category)
jokeURL.RawQuery = query.Encode()
}
return jokeURL, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment