Do not export Client.Addr.

This commit is contained in:
Владислав Весельский 2025-02-06 19:05:52 +03:00
parent 267969bc16
commit 68585b6448
1 changed files with 16 additions and 16 deletions

View File

@ -17,24 +17,24 @@ const tracerName = "git.bit5.ru/backend/push_client"
var tracer = otel.Tracer(tracerName) var tracer = otel.Tracer(tracerName)
type Client struct { type Client struct {
Addr string addr string
} }
func NewClient(addr string) *Client { func NewClient(addr string) *Client {
return &Client{ return &Client{
Addr: addr, addr: addr,
} }
} }
func (c *Client) ServerInfo() (*push_common.ServerInfo, error) { func (c *Client) ServerInfo() (*push_common.ServerInfo, error) {
var info push_common.ServerInfo var info push_common.ServerInfo
err := httpGet(c.Addr+"/api/server_info", &info) err := httpGet(c.addr+"/api/server_info", &info)
return &info, err return &info, err
} }
func (c *Client) UserPushPreviews(ctx context.Context) ([]*push_common.PushPreview, error) { func (c *Client) UserPushPreviews(ctx context.Context) ([]*push_common.PushPreview, error) {
var previews []*push_common.PushPreview var previews []*push_common.PushPreview
if err := httpGet(c.Addr+"/api/push/previews/user", &previews); err != nil { if err := httpGet(c.addr+"/api/push/previews/user", &previews); err != nil {
return nil, err return nil, err
} }
return previews, nil return previews, nil
@ -42,14 +42,14 @@ func (c *Client) UserPushPreviews(ctx context.Context) ([]*push_common.PushPrevi
func (c *Client) AutoPushPreviews() ([]*push_common.PushPreview, error) { func (c *Client) AutoPushPreviews() ([]*push_common.PushPreview, error) {
var previews []*push_common.PushPreview var previews []*push_common.PushPreview
if err := httpGet(c.Addr+"/api/push/previews/auto", &previews); err != nil { if err := httpGet(c.addr+"/api/push/previews/auto", &previews); err != nil {
return nil, err return nil, err
} }
return previews, nil return previews, nil
} }
func (c *Client) NewPush(req push_common.PushRequest) (int, error) { func (c *Client) NewPush(req push_common.PushRequest) (int, error) {
resp, err := httpPostDataDeprecated(c.Addr+"/api/push/add", req) resp, err := httpPostDataDeprecated(c.addr+"/api/push/add", req)
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -60,7 +60,7 @@ func (c *Client) SchedulePush(ctx context.Context, def *push_common.PushDef) (in
_, span := tracer.Start(ctx, "Client.SchedulePush") _, span := tracer.Start(ctx, "Client.SchedulePush")
defer span.End() defer span.End()
resp, err := httpPostDataDeprecated(c.Addr+"/api/push/schedule", def) resp, err := httpPostDataDeprecated(c.addr+"/api/push/schedule", def)
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -68,11 +68,11 @@ func (c *Client) SchedulePush(ctx context.Context, def *push_common.PushDef) (in
} }
func (c *Client) StartPush(id int) error { func (c *Client) StartPush(id int) error {
return httpPost(c.Addr + "/api/push/start/" + strconv.Itoa(id)) return httpPost(c.addr + "/api/push/start/" + strconv.Itoa(id))
} }
func (c *Client) PausePush(id int) error { func (c *Client) PausePush(id int) error {
return httpPost(c.Addr + "/api/push/pause/" + strconv.Itoa(id)) return httpPost(c.addr + "/api/push/pause/" + strconv.Itoa(id))
} }
/* /*
@ -82,25 +82,25 @@ func (c *Client) ArchivePush(ctx context.Context, id int) error {
*/ */
func (c *Client) DelPush(ctx context.Context, id int) error { func (c *Client) DelPush(ctx context.Context, id int) error {
return httpPost(c.Addr + "/api/push/del/" + strconv.Itoa(id)) return httpPost(c.addr + "/api/push/del/" + strconv.Itoa(id))
} }
func (c *Client) GetPush(id int) (*push_common.Push, error) { func (c *Client) GetPush(id int) (*push_common.Push, error) {
var push push_common.Push var push push_common.Push
err := httpGet(c.Addr+"/api/push/get/"+strconv.Itoa(id), &push) err := httpGet(c.addr+"/api/push/get/"+strconv.Itoa(id), &push)
return &push, err return &push, err
} }
func (c *Client) GetPushPayload(id int) (*push_common.PushPayload, error) { func (c *Client) GetPushPayload(id int) (*push_common.PushPayload, error) {
var payload *push_common.PushPayload var payload *push_common.PushPayload
if err := httpGet(c.Addr+"/api/push/get_payload/"+strconv.Itoa(id), &payload); err != nil { if err := httpGet(c.addr+"/api/push/get_payload/"+strconv.Itoa(id), &payload); err != nil {
return nil, err return nil, err
} }
return payload, nil return payload, nil
} }
func (c *Client) EditPushRequest(id int, payload push_common.PushPayload) error { func (c *Client) EditPushRequest(id int, payload push_common.PushPayload) error {
_, err := httpPostDataDeprecated(c.Addr+"/api/push/edit/"+strconv.Itoa(id), payload) _, err := httpPostDataDeprecated(c.addr+"/api/push/edit/"+strconv.Itoa(id), payload)
return err return err
} }
@ -109,7 +109,7 @@ func (c *Client) GetIncomingPushes(ctx context.Context) ([]*push_common.Incoming
defer span.End() defer span.End()
var pushes []*push_common.IncomingPushInfo var pushes []*push_common.IncomingPushInfo
if err := httpGet(c.Addr+"/api/push/incoming_pushes", &pushes); err != nil { if err := httpGet(c.addr+"/api/push/incoming_pushes", &pushes); err != nil {
return nil, errors.WithMessage(err, "Can not load incoming pushes.") return nil, errors.WithMessage(err, "Can not load incoming pushes.")
} }
@ -121,7 +121,7 @@ func (c *Client) GetPushesToClean(ctx context.Context) ([]*push_common.Push, err
defer span.End() defer span.End()
var lst []*push_common.Push var lst []*push_common.Push
if err := httpGet(c.Addr+"/api/push/list_to_clean", &lst); err != nil { if err := httpGet(c.addr+"/api/push/list_to_clean", &lst); err != nil {
return nil, errors.WithMessage(err, "Can not load list_to_clean.") return nil, errors.WithMessage(err, "Can not load list_to_clean.")
} }
return lst, nil return lst, nil
@ -131,6 +131,6 @@ func (c *Client) LaunchPush(ctx context.Context, logger logr.Logger, launchReque
_, span := tracer.Start(ctx, "Client.LaunchPush") _, span := tracer.Start(ctx, "Client.LaunchPush")
defer span.End() defer span.End()
_, err := httpPostData(logger, c.Addr+"/api/push/launch", launchRequest) _, err := httpPostData(logger, c.addr+"/api/push/launch", launchRequest)
return err return err
} }