Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions fcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (
type FcmClient struct {
ApiKey string
Message FcmMsg
client *http.Client
}

// FcmMsg represents fcm request message
Expand Down Expand Up @@ -90,8 +91,13 @@ type NotificationPayload struct {

// NewFcmClient init and create fcm client
func NewFcmClient(apiKey string) *FcmClient {
return NewFcmClientWithHttp(apiKey, &http.Client{})
}

func NewFcmClientWithHttp(apiKey string, client *http.Client) *FcmClient {
fcmc := new(FcmClient)
fcmc.ApiKey = apiKey
fcmc.client = client

return fcmc
}
Expand Down Expand Up @@ -166,8 +172,7 @@ func (this *FcmClient) sendOnce() (*FcmResponseStatus, error) {
request.Header.Set("Authorization", this.apiKeyHeader())
request.Header.Set("Content-Type", "application/json")

client := &http.Client{}
response, err := client.Do(request)
response, err := this.client.Do(request)

if err != nil {
return fcmRespStatus, err
Expand Down