Migrating to unified logger interface
This commit is contained in:
parent
07c16aab13
commit
02628c6622
|
@ -0,0 +1 @@
|
||||||
|
tags
|
10
fcm.go
10
fcm.go
|
@ -21,7 +21,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
|
|
||||||
"git.bit5.ru/backend/colog"
|
"github.com/go-logr/logr"
|
||||||
"git.bit5.ru/backend/errors"
|
"git.bit5.ru/backend/errors"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
@ -80,10 +80,10 @@ type Client struct {
|
||||||
cfg ClientConfig
|
cfg ClientConfig
|
||||||
ts oauth2.TokenSource
|
ts oauth2.TokenSource
|
||||||
hc *http.Client
|
hc *http.Client
|
||||||
logger *colog.CoLog
|
logger logr.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(cfg ClientConfig, ts oauth2.TokenSource, hc *http.Client, logger *colog.CoLog) *Client {
|
func NewClient(cfg ClientConfig, ts oauth2.TokenSource, hc *http.Client, logger logr.Logger) *Client {
|
||||||
return &Client{
|
return &Client{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
ts: ts,
|
ts: ts,
|
||||||
|
@ -120,7 +120,7 @@ func (c *Client) doSendRequest(req SendRequest) (SendResponse, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return SendResponse{}, errors.WithStack(err)
|
return SendResponse{}, errors.WithStack(err)
|
||||||
}
|
}
|
||||||
c.logger.Logf("sending message: %s", data)
|
c.logger.Info("sending", "message", data)
|
||||||
|
|
||||||
request, err := http.NewRequest(http.MethodPost, c.cfg.SendEndpoint, bytes.NewReader(data))
|
request, err := http.NewRequest(http.MethodPost, c.cfg.SendEndpoint, bytes.NewReader(data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -280,7 +280,7 @@ func (c *Client) makeMultiSendResponse(response *http.Response, totalCount int)
|
||||||
|
|
||||||
responses = append(responses, resp)
|
responses = append(responses, resp)
|
||||||
if resp.HasError() {
|
if resp.HasError() {
|
||||||
c.logger.Logf("error: %+v", *resp.Error)
|
c.logger.Info("fail", "error", fmt.Sprintf("%+v", *resp.Error))
|
||||||
fails++
|
fails++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module git.bit5.ru/backend/fcm
|
||||||
go 1.13
|
go 1.13
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.bit5.ru/backend/colog v1.0.0
|
|
||||||
git.bit5.ru/backend/errors v1.0.0
|
git.bit5.ru/backend/errors v1.0.0
|
||||||
golang.org/x/oauth2 v0.1.0
|
golang.org/x/oauth2 v0.1.0
|
||||||
|
github.com/go-logr/logr v1.2.3
|
||||||
)
|
)
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -93,6 +93,8 @@ github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeME
|
||||||
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
||||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||||
|
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
|
||||||
|
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||||
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||||
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||||
|
|
Loading…
Reference in New Issue