This commit is contained in:
PB
2022-12-25 22:59:04 +01:00
parent f141f6c34f
commit 2e40ca75c9
3 changed files with 12 additions and 15 deletions

View File

@@ -10,16 +10,13 @@ import (
"github.com/go-redis/redis/v8"
)
const (
HEADER_USER_AGENT = "order-httpclient"
)
type HttpClient struct {
ua string
redis *redis.Client
}
func NewHttpClient(redis *redis.Client) *HttpClient {
return &HttpClient{redis}
func NewHttpClient(ua string, redis *redis.Client) *HttpClient {
return &HttpClient{ua, redis}
}
func (c *HttpClient) SendGet(api, url string, data, out any) error {
@@ -67,7 +64,7 @@ func (c *HttpClient) sendRequest(api, url, method string, data any) (*http.Respo
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", HEADER_USER_AGENT)
req.Header.Set("User-Agent", c.ua)
res, err := client.Do(req)
if err != nil {
return nil, err
@@ -78,7 +75,7 @@ func (c *HttpClient) sendRequest(api, url, method string, data any) (*http.Respo
}
func (c *HttpClient) getApiUrl(api string) string {
ctx, key, apiAddr := context.Background(), "internal__"+api+"_ips", api
ctx, key, apiAddr := context.Background(), "internal__"+api+"__ips", api
// FIXME: key name ^^
cmd := c.redis.LLen(ctx, key)
if cmd.Err() == nil {