mirror of
https://github.com/Penguin-71630/meme-bot-frontend-dc.git
synced 2026-03-12 20:40:16 +08:00
Refactor: cleanup
- Introduce tracing - Introduce cobra / viper framework - Introduce resty client - Seperate files in api/ and bot/ - Trim unused functions
This commit is contained in:
33
api/getImages.go
Normal file
33
api/getImages.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/Penguin-71630/meme-bot-frontend-dc/tracing"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func (c *Client) GetImages(
|
||||
search string,
|
||||
limit, page int,
|
||||
) (ImagesResponse, error) {
|
||||
var res ImagesResponse
|
||||
resp, err := c.client.R().
|
||||
SetResult(&res).
|
||||
SetQueryParam("search", search).
|
||||
SetQueryParam("limit", strconv.Itoa(limit)).
|
||||
SetQueryParam("page", strconv.Itoa(page)).
|
||||
Get("/api/images")
|
||||
|
||||
if err != nil || resp.StatusCode() != http.StatusOK {
|
||||
tracing.Logger.Ctx(resp.Request.Context()).
|
||||
Error("failed to get api images",
|
||||
zap.String("search", search),
|
||||
zap.Int("limit", limit),
|
||||
zap.Int("page", page),
|
||||
zap.Error(err))
|
||||
return ImagesResponse{}, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
Reference in New Issue
Block a user