refactor: moved http.Client to model.RequestContext
Signed-off-by: SoXX <soxx@fenpa.ws>
This commit is contained in:
parent
e52735fe26
commit
50e8cc24cb
@ -12,14 +12,13 @@ import (
|
|||||||
// GetPool retrieves a pool by its ID from the e621 API.
|
// GetPool retrieves a pool 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 pool to retrieve.
|
// - ID: The ID of the pool to retrieve.
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// - model.Pool: The retrieved pool.
|
// - model.Pool: The retrieved pool.
|
||||||
// - 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 GetPool(client http.Client, requestContext model.RequestContext, ID string) (model.Pool, error) {
|
func GetPool(requestContext model.RequestContext, ID string) (model.Pool, error) {
|
||||||
// Create a new HTTP GET request to fetch the pool information.
|
// Create a new HTTP GET request to fetch the pool information.
|
||||||
r, err := http.NewRequest("GET", fmt.Sprintf("%s/pools/%s.json", requestContext.Host, ID), nil)
|
r, err := http.NewRequest("GET", fmt.Sprintf("%s/pools/%s.json", requestContext.Host, ID), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -33,7 +32,7 @@ func GetPool(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 Pool struct and the error.
|
// Log the error and return an empty Pool struct and the error.
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@ -64,14 +63,13 @@ func GetPool(client http.Client, requestContext model.RequestContext, ID string)
|
|||||||
// GetPools retrieves a list of pools from the e621 API based on query parameters.
|
// GetPools retrieves a list of pools 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.
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// - []model.Pool: A slice of pools.
|
// - []model.Pool: A slice of pools.
|
||||||
// - 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 GetPools(client http.Client, requestContext model.RequestContext, query map[string]string) ([]model.Pool, error) {
|
func GetPools(requestContext model.RequestContext, query map[string]string) ([]model.Pool, error) {
|
||||||
// Create a new HTTP GET request.
|
// Create a new HTTP GET request.
|
||||||
r, err := http.NewRequest("GET", fmt.Sprintf("%s/pools.json", requestContext.Host), nil)
|
r, err := http.NewRequest("GET", fmt.Sprintf("%s/pools.json", requestContext.Host), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -90,7 +88,7 @@ func GetPools(client http.Client, requestContext model.RequestContext, query map
|
|||||||
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.Print(err)
|
log.Print(err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user