refactor: moved http.Client to model.RequestContext

Signed-off-by: SoXX <soxx@fenpa.ws>
This commit is contained in:
SoXX 2023-10-23 10:29:02 +02:00
parent 4b9a01ee4a
commit e063db1d59

View File

@ -12,14 +12,13 @@ import (
// GetTag retrieves a tag by its ID from the e621 API. // GetTag retrieves a tag by its ID from the e621 API.
// //
// 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. // - requestContext: The context for the API request, including the host, user agent, username, and API key.
// - ID: The ID of the tag to retrieve. // - ID: The ID of the tag to retrieve.
// //
// Returns: // Returns:
// - model.Tag: The retrieved tag. // - model.Tag: The retrieved tag.
// - error: An error, if any, encountered during the API request or response handling. // - 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. // 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) r, err := http.NewRequest("GET", fmt.Sprintf("%s/tags/%s.json", requestContext.Host, ID), nil)
if err != nil { if err != nil {
@ -33,7 +32,7 @@ func GetTag(client http.Client, requestContext model.RequestContext, ID string)
r.SetBasicAuth(requestContext.Username, requestContext.APIKey) r.SetBasicAuth(requestContext.Username, requestContext.APIKey)
// Send the request using the provided http.Client. // Send the request using the provided http.Client.
resp, err := client.Do(r) resp, err := requestContext.Client.Do(r)
if err != nil { if err != nil {
// Log the error and return an empty Tag struct and the error. // Log the error and return an empty Tag struct and the error.
log.Println(err) 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. // GetTags retrieves a list of tags from the e621 API based on query parameters.
// //
// 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. // - 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. // - query: A map containing additional query parameters for the API request.
// //