refactor: moved http.Client to model.RequestContext
Signed-off-by: SoXX <soxx@fenpa.ws>
This commit is contained in:
parent
4b9a01ee4a
commit
e063db1d59
@ -12,14 +12,13 @@ import (
|
||||
// GetTag retrieves a tag by its ID from the e621 API.
|
||||
//
|
||||
// Parameters:
|
||||
// - client: An http.Client used to make the API request.
|
||||
// - requestContext: The context for the API request, including the host, user agent, username, and API key.
|
||||
// - ID: The ID of the tag to retrieve.
|
||||
//
|
||||
// Returns:
|
||||
// - model.Tag: The retrieved tag.
|
||||
// - error: An error, if any, encountered during the API request or response handling.
|
||||
func GetTag(client http.Client, requestContext model.RequestContext, ID string) (model.Tag, error) {
|
||||
func GetTag(requestContext model.RequestContext, ID string) (model.Tag, error) {
|
||||
// Create a new HTTP GET request to fetch tag information.
|
||||
r, err := http.NewRequest("GET", fmt.Sprintf("%s/tags/%s.json", requestContext.Host, ID), nil)
|
||||
if err != nil {
|
||||
@ -33,7 +32,7 @@ func GetTag(client http.Client, requestContext model.RequestContext, ID string)
|
||||
r.SetBasicAuth(requestContext.Username, requestContext.APIKey)
|
||||
|
||||
// Send the request using the provided http.Client.
|
||||
resp, err := client.Do(r)
|
||||
resp, err := requestContext.Client.Do(r)
|
||||
if err != nil {
|
||||
// Log the error and return an empty Tag struct and the error.
|
||||
log.Println(err)
|
||||
@ -65,7 +64,6 @@ func GetTag(client http.Client, requestContext model.RequestContext, ID string)
|
||||
// GetTags retrieves a list of tags from the e621 API based on query parameters.
|
||||
//
|
||||
// Parameters:
|
||||
// - client: An http.Client used to make the API request.
|
||||
// - requestContext: The context for the API request, including the host, user agent, username, and API key.
|
||||
// - query: A map containing additional query parameters for the API request.
|
||||
//
|
||||
|
Reference in New Issue
Block a user