Compare commits
5 Commits
Author | SHA1 | Date |
---|---|---|
|
a25fdc474a | |
|
c76b172a3a | |
|
eb024fd00c | |
|
d2b252d82a | |
|
250cfe9d33 |
26
fcm.go
26
fcm.go
|
@ -47,7 +47,7 @@ var (
|
|||
AuthScopes = []string{"https://www.googleapis.com/auth/firebase.messaging"}
|
||||
)
|
||||
|
||||
func MakeSendEndpoint(projectId string) string {
|
||||
func makeSendEndpoint(projectId string) string {
|
||||
return fmt.Sprintf("https://fcm.googleapis.com/v1/projects/%s/messages:send", projectId)
|
||||
}
|
||||
|
||||
|
@ -79,23 +79,19 @@ func ReadCredentialsFromFile(filename string) (Credentials, error) {
|
|||
return c, nil
|
||||
}
|
||||
|
||||
type ClientConfig struct {
|
||||
SendEndpoint string
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
cfg ClientConfig
|
||||
ts oauth2.TokenSource
|
||||
hc *http.Client
|
||||
logger logr.Logger
|
||||
sendEndpoint string
|
||||
ts oauth2.TokenSource
|
||||
hc *http.Client
|
||||
logger logr.Logger
|
||||
}
|
||||
|
||||
func NewClient(projectId string, cfg ClientConfig, ts oauth2.TokenSource, hc *http.Client, logger logr.Logger) *Client {
|
||||
func NewClient(projectId string, ts oauth2.TokenSource, hc *http.Client, logger logr.Logger) *Client {
|
||||
return &Client{
|
||||
cfg: cfg,
|
||||
ts: ts,
|
||||
hc: hc,
|
||||
logger: logger,
|
||||
sendEndpoint: makeSendEndpoint(projectId),
|
||||
ts: ts,
|
||||
hc: hc,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -194,7 +190,7 @@ func (c *Client) doSendRequest(ctx context.Context, req SendRequest, loggerEnabl
|
|||
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.sendEndpoint, bytes.NewReader(data))
|
||||
if err != nil {
|
||||
span.SetStatus(codes.Error, err.Error())
|
||||
span.RecordError(err)
|
||||
|
|
Loading…
Reference in New Issue