API fix
This commit is contained in:
13
api/http.go
13
api/http.go
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user