diff --git a/README.md b/README.md index ad10bc1..be56376 100644 --- a/README.md +++ b/README.md @@ -94,34 +94,11 @@ Response example: {"result": "ok"} ``` -### POST /push/fcm +### POST /push/fcm **Deprecated** -To delivery remote notifications via FCM (legacy) API to user's devices. +This API has been deleted at v0.6.0. Use `/push/fcm/v1` instead. -Post body format is equal to it for FCM legacy origin server. - -example: -```json -{ - "registration_ids": [ - "token1", - "token2" - ], - "data": { - "id": "2", - "message": "Test2" - }, - "notification": { - "title": "message_title", - "body": "message_body" - } -} -``` - -Response example: -```json -{"result": "ok"} -``` +See also https://firebase.google.com/docs/cloud-messaging/migrate-v1 . ### POST /push/fcm/v1 diff --git a/apns/client.go b/apns/client.go index 7f7ed62..89c3c26 100644 --- a/apns/client.go +++ b/apns/client.go @@ -5,9 +5,9 @@ import ( "crypto/tls" "encoding/json" "fmt" - "io/ioutil" "net/http" "net/url" + "os" "time" "github.com/kayac/Gunfish/config" @@ -151,12 +151,12 @@ func NewClient(conf config.SectionApns) (*Client, error) { useAuthToken := conf.Kid != "" && conf.TeamID != "" tr := &http.Transport{} if !useAuthToken { - certPEMBlock, err := ioutil.ReadFile(conf.CertFile) + certPEMBlock, err := os.ReadFile(conf.CertFile) if err != nil { return nil, err } - keyPEMBlock, err := ioutil.ReadFile(conf.KeyFile) + keyPEMBlock, err := os.ReadFile(conf.KeyFile) if err != nil { return nil, err } @@ -172,7 +172,7 @@ func NewClient(conf config.SectionApns) (*Client, error) { return nil, err } - key, err := ioutil.ReadFile(conf.KeyFile) + key, err := os.ReadFile(conf.KeyFile) if err != nil { return nil, err } diff --git a/config/config.go b/config/config.go index c2a2e7b..e44cf3a 100644 --- a/config/config.go +++ b/config/config.go @@ -6,7 +6,7 @@ import ( "crypto/x509" "encoding/json" "fmt" - "io/ioutil" + "os" "time" "github.com/kayac/Gunfish/fcmv1" @@ -125,10 +125,7 @@ func (c *Config) validateConfig() error { } } if c.FCM.APIKey != "" { - c.FCM.Enabled = true - if err := c.validateConfigFCM(); err != nil { - return errors.Wrap(err, "[fcm]") - } + return errors.New("[fcm] legacy is not supported anymore. Please use [fcm_v1]") } if c.FCMv1.GoogleApplicationCredentials != "" { c.FCMv1.Enabled = true @@ -158,12 +155,8 @@ func (c *Config) validateConfigProvider() error { return nil } -func (c *Config) validateConfigFCM() error { - return nil -} - func (c *Config) validateConfigFCMv1() error { - b, err := ioutil.ReadFile(c.FCMv1.GoogleApplicationCredentials) + b, err := os.ReadFile(c.FCMv1.GoogleApplicationCredentials) if err != nil { return err } diff --git a/fcm/client.go b/fcm/client.go deleted file mode 100644 index bdd2a1c..0000000 --- a/fcm/client.go +++ /dev/null @@ -1,104 +0,0 @@ -package fcm - -import ( - "bytes" - "encoding/json" - "fmt" - "net/http" - "net/url" - "time" -) - -// fcm Client const variables -const ( - DefaultFCMEndpoint = "https://fcm.googleapis.com/fcm/send" - ClientTimeout = time.Second * 10 -) - -// Client is FCM client -type Client struct { - endpoint *url.URL - apiKey string - Client *http.Client -} - -// Send sends notifications to fcm -func (c *Client) Send(p Payload) ([]Result, error) { - req, err := c.NewRequest(p) - if err != nil { - return nil, err - } - - res, err := c.Client.Do(req) - if err != nil { - return nil, err - } - defer res.Body.Close() - - var body ResponseBody - dec := json.NewDecoder(res.Body) - if err = dec.Decode(&body); err != nil { - return nil, NewError(res.StatusCode, err.Error()) - } - - if res.StatusCode != http.StatusOK { - return nil, NewError(res.StatusCode, "status is not OK") - } - if len(p.RegistrationIDs) == 0 && len(body.Results) == 1 { - r := body.Results[0] - r.To = p.To - r.StatusCode = res.StatusCode - return []Result{r}, nil - } else if len(p.RegistrationIDs) > 0 && len(p.RegistrationIDs) == len(body.Results) { - ret := make([]Result, 0, len(body.Results)) - for i, r := range body.Results { - r.RegistrationID = p.RegistrationIDs[i] - r.StatusCode = res.StatusCode - ret = append(ret, r) - } - return ret, nil - } - - return nil, NewError(res.StatusCode, "unexpected response") -} - -// NewRequest creates request for fcm -func (c *Client) NewRequest(p Payload) (*http.Request, error) { - data, err := json.Marshal(p) - if err != nil { - return nil, err - } - - req, err := http.NewRequest("POST", c.endpoint.String(), bytes.NewReader(data)) - if err != nil { - return nil, err - } - req.Header.Set("Authorization", fmt.Sprintf("key=%s", c.apiKey)) - req.Header.Set("Content-Type", "application/json") - - return req, nil -} - -// NewClient establishes a http connection with fcm -func NewClient(apikey string, endpoint *url.URL, timeout time.Duration) (*Client, error) { - client := &http.Client{ - Timeout: timeout, - } - - c := &Client{ - apiKey: apikey, - Client: client, - } - - if endpoint != nil { - c.endpoint = endpoint - } else { - if ep, err := url.Parse(DefaultFCMEndpoint); err != nil { - return nil, err - } else { - c.endpoint = ep - } - } - - return c, nil -} diff --git a/fcm/error.go b/fcm/error.go deleted file mode 100644 index 0601379..0000000 --- a/fcm/error.go +++ /dev/null @@ -1,50 +0,0 @@ -package fcm - -import "fmt" - -type FCMErrorResponseCode int - -// Error const variables -const ( - // 200 + error - MissingRegistration FCMErrorResponseCode = iota - InvalidRegistration - NotRegistered - InvalidPackageName - MismatchSenderId - MessageTooBig - InvalidDataKey - InvalidTtl - DeviceMessageRateExceeded - TopicsMessageRateExceeded - InvalidApnsCredentials - - // NOTES: 40x response has no error message - AuthenticationError // 401 - InvalidJSON // 400 - - // 5xx or 200 - Unavailable - - // 500 or 200 - InternalServerError - - // UnknownError - UnknownError -) - -type Error struct { - StatusCode int - Reason string -} - -func (e Error) Error() string { - return fmt.Sprintf("status:%d reason:%s", e.StatusCode, e.Reason) -} - -func NewError(s int, r string) Error { - return Error{ - StatusCode: s, - Reason: r, - } -} diff --git a/fcm/fcmerrorresponsecode_string.go b/fcm/fcmerrorresponsecode_string.go deleted file mode 100644 index 108e6f3..0000000 --- a/fcm/fcmerrorresponsecode_string.go +++ /dev/null @@ -1,16 +0,0 @@ -// Code generated by "stringer -type FCMErrorResponseCode error.go"; DO NOT EDIT - -package fcm - -import "fmt" - -const _FCMErrorResponseCode_name = "MissingRegistrationInvalidRegistrationNotRegisteredInvalidPackageNameMismatchSenderIdMessageTooBigInvalidDataKeyInvalidTtlDeviceMessageRateExceededTopicsMessageRateExceededInvalidApnsCredentialsAuthenticationErrorInvalidJSONUnavailableInternalServerErrorUnknownError" - -var _FCMErrorResponseCode_index = [...]uint16{0, 19, 38, 51, 69, 85, 98, 112, 122, 147, 172, 194, 213, 224, 235, 254, 266} - -func (i FCMErrorResponseCode) String() string { - if i < 0 || i >= FCMErrorResponseCode(len(_FCMErrorResponseCode_index)-1) { - return fmt.Sprintf("FCMErrorResponseCode(%d)", i) - } - return _FCMErrorResponseCode_name[_FCMErrorResponseCode_index[i]:_FCMErrorResponseCode_index[i+1]] -} diff --git a/fcm/request.go b/fcm/request.go deleted file mode 100644 index 9338d0c..0000000 --- a/fcm/request.go +++ /dev/null @@ -1,35 +0,0 @@ -package fcm - -// Payload for fcm -type Payload struct { - To string `json:"to,omitempty"` - RegistrationIDs []string `json:"registration_ids,omitempty"` - CollapseKey string `json:"collapse_key,omitempty"` - Priority string `json:"priority,omitempty"` - ContentAvailable bool `json:"content_available,omitempty"` - DelayWhileIdle bool `json:"delay_while_idle,omitempty"` - TimeToLive uint `json:"time_to_live,omitempty"` - RestrictedPackageName string `json:"restricted_package_name,omitempty"` - DryRun bool `json:"dry_run,omitempty"` - Data *Data `json:"data,omitempty"` - Notification *Notification `json:"notification,omitempty"` -} - -// Data is payload of fcm message -type Data map[string]interface{} - -// Notification is payload of a FCM message -type Notification struct { - Title string `json:"title,omitempty"` - Body string `json:"body,omitempty"` - Icon string `json:"icon,omitempty"` - Sound string `json:"sound,omitempty"` - Badge string `json:"badge,omitempty"` - Tag string `json:"tag,omitempty"` - Color string `json:"color,omitempty"` - ClickAction string `json:"click_action,omitempty"` - BodyLocKey string `json:"body_loc_key,omitempty"` - BodyLocArgs string `json:"body_loc_args,omitempty"` - TitleLocArgs string `json:"title_loc_args,omitempty"` - TitleLocKey string `json:"title_loc_key,omitempty"` -} diff --git a/fcm/request_test.go b/fcm/request_test.go deleted file mode 100644 index 530b437..0000000 --- a/fcm/request_test.go +++ /dev/null @@ -1,71 +0,0 @@ -package fcm - -import ( - "encoding/json" - "testing" - - "github.com/google/go-cmp/cmp" -) - -func TestUnmarshalPayload(t *testing.T) { - var p Payload - if err := json.Unmarshal([]byte(buildPayloadJSON()), &p); err != nil { - t.Error(err) - } - - if diff := cmp.Diff(p, buildPayload()); diff != "" { - t.Errorf("mismatch decoded payload diff: %s", diff) - } -} - -func TestMarshalPayload(t *testing.T) { - p := buildPayload() - output, err := json.Marshal(p) - if err != nil { - t.Error(err) - } - - expected := `{"registration_ids":["registration_id_1","registration_id_2","registration_id_3"],"data":{"message":"sample message","sample_key":"sample key"},"notification":{"title":"message_title","body":"message_body"}}` - - if string(output) != expected { - t.Errorf("should be expected json: got=%s, expected=%s", output, expected) - } -} - -func buildPayload() Payload { - dataMap := &Data{ - "sample_key": "sample key", - "message": "sample message", - } - - return Payload{ - Notification: &Notification{ - Title: "message_title", - Body: "message_body", - }, - Data: dataMap, - RegistrationIDs: []string{ - "registration_id_1", - "registration_id_2", - "registration_id_3", - }, - } -} - -func buildPayloadJSON() string { - return `{ - "notification": { - "title": "message_title", - "body": "message_body" - }, - "data": { - "sample_key": "sample key", - "message": "sample message" - }, - "registration_ids": [ - "registration_id_1", - "registration_id_2", - "registration_id_3" - ] - }` -} diff --git a/fcm/response.go b/fcm/response.go deleted file mode 100644 index 1b7e6a1..0000000 --- a/fcm/response.go +++ /dev/null @@ -1,74 +0,0 @@ -package fcm - -import ( - "encoding/json" - "errors" -) - -const Provider = "fcm" - -// ResponseBody fcm response body -type ResponseBody struct { - MulticastID int `json:"multicast_id"` - Success int `json:"success"` - Failure int `json:"failure"` - CanonicalIDs int `json:"canonical_ids"` - Results []Result `json:"results,omitempty"` - MessageID int `json:"message_id,omitempty"` -} - -// Result is the status of a processed FCMResponse -type Result struct { - StatusCode int `json:"status,omitempty"` - MessageID string `json:"message_id,omitempty"` - To string `json:"to,omitempty"` - RegistrationID string `json:"registration_id,omitempty"` - Error string `json:"error,omitempty"` -} - -func (r Result) Err() error { - if r.Error != "" { - return errors.New(r.Error) - } - return nil -} - -func (r Result) Status() int { - return r.StatusCode -} - -func (r Result) RecipientIdentifier() string { - if r.To != "" { - return r.To - } - return r.RegistrationID -} - -func (r Result) ExtraKeys() []string { - return []string{"message_id", "error"} -} - -func (r Result) Provider() string { - return Provider -} - -func (r Result) ExtraValue(key string) string { - switch key { - case "message_id": - return r.MessageID - case "error": - return r.Error - } - return "" -} - -func (r Result) MarshalJSON() ([]byte, error) { - type Alias Result - return json.Marshal(struct { - Provider string `json:"provider"` - Alias - }{ - Provider: Provider, - Alias: (Alias)(r), - }) -} diff --git a/fcm/response_test.go b/fcm/response_test.go deleted file mode 100644 index 3081940..0000000 --- a/fcm/response_test.go +++ /dev/null @@ -1,87 +0,0 @@ -package fcm - -import ( - "encoding/json" - "testing" - - "github.com/google/go-cmp/cmp" -) - -func TestUnmarshalResponse(t *testing.T) { - var r ResponseBody - if err := json.Unmarshal([]byte(buildResponseBodyJSON()), &r); err != nil { - t.Error(err) - } - - if diff := cmp.Diff(r, buildResponseBody()); diff != "" { - t.Errorf("mismatch decoded payload diff: %s", diff) - } -} - -func TestMarshalResponse(t *testing.T) { - p := buildResponseBody() - output, err := json.Marshal(p) - if err != nil { - t.Error(err) - } - - expected := `{"multicast_id":5302270091026410054,"success":3,"failure":0,"canonical_ids":0,"results":[{"provider":"fcm","status":200,"message_id":"0:1487073977923500%caa8591dcaa8591d"},{"provider":"fcm","status":200,"message_id":"0:1487073977923148%caa8591dcaa8591d"},{"provider":"fcm","status":200,"message_id":"0:1487073977924484%caa8591dcaa8591d"}]}` - - if string(output) != expected { - t.Errorf("mismatch decoded response:\ngot=%s\nexpected=%s", output, expected) - } -} - -func buildResponseBody() ResponseBody { - return ResponseBody{ - MulticastID: 5302270091026410054, - Success: 3, - Failure: 0, - CanonicalIDs: 0, - Results: []Result{ - Result{ - StatusCode: 200, - MessageID: "0:1487073977923500%caa8591dcaa8591d", - }, - Result{ - StatusCode: 200, - MessageID: "0:1487073977923148%caa8591dcaa8591d", - }, - Result{ - StatusCode: 200, - MessageID: "0:1487073977924484%caa8591dcaa8591d", - }, - }, - } -} - -func buildResponseBodyJSON() string { - return `{ - "multicast_id": 5302270091026410054, - "success": 3, - "failure": 0, - "canonical_ids": 0, - "results": [ - { "status":200, "message_id": "0:1487073977923500%caa8591dcaa8591d" }, - { "status":200, "message_id": "0:1487073977923148%caa8591dcaa8591d" }, - { "status":200, "message_id": "0:1487073977924484%caa8591dcaa8591d" } - ] - }` -} - -func TestResult(t *testing.T) { - result := Result{ - StatusCode: 200, - MessageID: "msgid", - RegistrationID: "xxxx", - Error: "NotRegistered", - } - b, err := result.MarshalJSON() - if err != nil { - t.Error(err) - } - t.Logf("%s", string(b)) - if string(b) != `{"provider":"fcm","status":200,"message_id":"msgid","registration_id":"xxxx","error":"NotRegistered"}` { - t.Errorf("unexpected encoded json: %s", string(b)) - } -} diff --git a/server.go b/server.go index 253e651..290df28 100644 --- a/server.go +++ b/server.go @@ -20,7 +20,6 @@ import ( stats_api "github.com/fukata/golang-stats-api-handler" "github.com/kayac/Gunfish/apns" "github.com/kayac/Gunfish/config" - "github.com/kayac/Gunfish/fcm" "github.com/kayac/Gunfish/fcmv1" "github.com/lestrrat-go/server-starter/listener" "github.com/sirupsen/logrus" @@ -146,16 +145,13 @@ func StartServer(conf config.Config, env Environment) { mux.HandleFunc("/push/apns", prov.PushAPNsHandler()) } if conf.FCM.Enabled { - LogWithFields(logrus.Fields{ - "type": "provider", - }).Infof("Enable endpoint /push/fcm") - mux.HandleFunc("/push/fcm", prov.PushFCMHandler(false)) + panic("FCM legacy is not supported") } if conf.FCMv1.Enabled { LogWithFields(logrus.Fields{ "type": "provider", }).Infof("Enable endpoint /push/fcm/v1") - mux.HandleFunc("/push/fcm/v1", prov.PushFCMHandler(true)) + mux.HandleFunc("/push/fcm/v1", prov.PushFCMHandler()) } mux.HandleFunc("/stats/app", prov.StatsHandler()) mux.HandleFunc("/stats/profile", stats_api.Handler) @@ -265,7 +261,7 @@ func (prov *Provider) PushAPNsHandler() http.HandlerFunc { }) } -func (prov *Provider) PushFCMHandler(v1 bool) http.HandlerFunc { +func (prov *Provider) PushFCMHandler() http.HandlerFunc { return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { atomic.AddInt64(&(srvStats.RequestCount), 1) @@ -286,7 +282,7 @@ func (prov *Provider) PushFCMHandler(v1 bool) http.HandlerFunc { } // create request for fcm - grs, err := newFCMRequests(req.Body, v1) + grs, err := newFCMRequests(req.Body) if err != nil { logrus.Warnf("bad request: %s", err) res.WriteHeader(http.StatusBadRequest) @@ -306,36 +302,27 @@ func (prov *Provider) PushFCMHandler(v1 bool) http.HandlerFunc { }) } -func newFCMRequests(src io.Reader, v1 bool) ([]Request, error) { +func newFCMRequests(src io.Reader) ([]Request, error) { dec := json.NewDecoder(src) reqs := []Request{} - if v1 { - count := 0 - PAYLOADS: - for { - var payload fcmv1.Payload - if err := dec.Decode(&payload); err != nil { - if err == io.EOF { - break PAYLOADS - } else { - return nil, err - } - } - count++ - if count >= fcmv1.MaxBulkRequests { - return nil, errors.New("Too many requests") + count := 0 +PAYLOADS: + for { + var payload fcmv1.Payload + if err := dec.Decode(&payload); err != nil { + if err == io.EOF { + break PAYLOADS + } else { + return nil, err } - reqs = append(reqs, Request{Notification: payload, Tries: 0}) } - return reqs, nil - } else { - var payload fcm.Payload - if err := dec.Decode(&payload); err != nil { - return nil, err + count++ + if count >= fcmv1.MaxBulkRequests { + return nil, errors.New("Too many requests") } reqs = append(reqs, Request{Notification: payload, Tries: 0}) - return reqs, nil } + return reqs, nil } func validateMethod(res http.ResponseWriter, req *http.Request) error { diff --git a/server_test.go b/server_test.go index 34a0ab4..68b8a79 100644 --- a/server_test.go +++ b/server_test.go @@ -53,9 +53,9 @@ func TestInvalidCertification(t *testing.T) { c, _ := config.LoadConfig("./test/gunfish_test.toml") c.Apns.CertFile = "./test/invalid.crt" c.Apns.KeyFile = "./test/invalid.key" - ss, err := gunfish.StartSupervisor(&c) + _, err := gunfish.StartSupervisor(&c) if err != nil { - t.Errorf("Expected supervisor cannot start because of using invalid certification files.: %v", ss) + t.Errorf("Expected supervisor cannot start %s", err) } } @@ -96,7 +96,7 @@ func TestSuccessToPostJson(t *testing.T) { func TestFailedToPostInvalidJson(t *testing.T) { sup, _ := gunfish.StartSupervisor(&conf) prov := &gunfish.Provider{Sup: sup} - handler := prov.PushFCMHandler(false) + handler := prov.PushFCMHandler() // missing `}` invalidJson := []byte(`{"registration_ids": ["xxxxxxxxx"], "data": {"message":"test"`) diff --git a/supervisor.go b/supervisor.go index 5081b6f..80fec60 100644 --- a/supervisor.go +++ b/supervisor.go @@ -15,7 +15,6 @@ import ( "github.com/kayac/Gunfish/apns" "github.com/kayac/Gunfish/config" - "github.com/kayac/Gunfish/fcm" "github.com/kayac/Gunfish/fcmv1" uuid "github.com/satori/go.uuid" "github.com/sirupsen/logrus" @@ -35,7 +34,6 @@ type Supervisor struct { // Worker sends notification to apns. type Worker struct { ac *apns.Client - fc *fcm.Client fcv1 *fcmv1.Client queue chan Request respq chan SenderResponse @@ -159,7 +157,6 @@ func StartSupervisor(conf *config.Config) (Supervisor, error) { for i := 0; i < conf.Provider.WorkerNum; i++ { var ( ac *apns.Client - fc *fcm.Client fcv1 *fcmv1.Client ) if conf.Apns.Enabled { @@ -172,13 +169,7 @@ func StartSupervisor(conf *config.Config) (Supervisor, error) { } } if conf.FCM.Enabled { - fc, err = fcm.NewClient(conf.FCM.APIKey, nil, fcm.ClientTimeout) - if err != nil { - LogWithFields(logrus.Fields{ - "type": "supervisor", - }).Errorf("failed to new client for fcm: %s", err.Error()) - break - } + return Supervisor{}, errors.New("FCM legacy is not supported") } if conf.FCMv1.Enabled { fcv1, err = fcmv1.NewClient(conf.FCMv1.TokenSource, conf.FCMv1.ProjectID, nil, fcmv1.ClientTimeout) @@ -196,7 +187,6 @@ func StartSupervisor(conf *config.Config) (Supervisor, error) { wgrp: &sync.WaitGroup{}, sn: SenderNum, ac: ac, - fc: fc, fcv1: fcv1, } @@ -272,7 +262,7 @@ func (s *Supervisor) spawnWorker(w Worker, conf *config.Config) { }).Debugf("Spawned a sender-%d-%d.", w.id, i) // spawnSender - go spawnSender(w.queue, w.respq, w.wgrp, w.ac, w.fc, w.fcv1) + go spawnSender(w.queue, w.respq, w.wgrp, w.ac, w.fcv1) } func() { @@ -311,20 +301,6 @@ func (w *Worker) receiveResponse(resp SenderResponse, retryq chan<- Request, cmd "resp_uid": resp.UID, } handleAPNsResponse(resp, retryq, cmdq, logf) - case fcm.Payload: - p := req.Notification.(fcm.Payload) - logf := logrus.Fields{ - "type": "worker", - "reg_ids_length": len(p.RegistrationIDs), - "notification": p.Notification, - "data": p.Data, - "worker_id": w.id, - "res_queue_size": len(w.respq), - "resend_cnt": req.Tries, - "response_time": resp.RespTime, - "resp_uid": resp.UID, - } - handleFCMResponse(resp, retryq, cmdq, logf) case fcmv1.Payload: p := req.Notification.(fcmv1.Payload) logf := logrus.Fields{ @@ -422,9 +398,6 @@ func handleFCMResponse(resp SenderResponse, retryq chan<- Request, cmdq chan Com // handle error response each registration_id atomic.AddInt64(&(srvStats.ErrCount), 1) switch err.Error() { - case fcm.InvalidRegistration.String(), fcm.NotRegistered.String(): - onResponse(result, errorResponseHandler.HookCmd(), cmdq) - LogWithFields(logf).Errorf("%s", err) case fcmv1.Unregistered, fcmv1.InvalidArgument, fcmv1.NotFound: onResponse(result, errorResponseHandler.HookCmd(), cmdq) LogWithFields(logf).Errorf("%s", err) @@ -451,7 +424,7 @@ func (w *Worker) receiveRequests(reqs *[]Request) { } } -func spawnSender(wq <-chan Request, respq chan<- SenderResponse, wgrp *sync.WaitGroup, ac *apns.Client, fc *fcm.Client, fcv1 *fcmv1.Client) { +func spawnSender(wq <-chan Request, respq chan<- SenderResponse, wgrp *sync.WaitGroup, ac *apns.Client, fcv1 *fcmv1.Client) { defer wgrp.Done() for req := range wq { var sres SenderResponse @@ -477,27 +450,6 @@ func spawnSender(wq <-chan Request, respq chan<- SenderResponse, wgrp *sync.Wait Err: err, UID: uuid.NewV4().String(), } - case fcm.Payload: - if fc == nil { - LogWithFields(logrus.Fields{"type": "sender"}). - Errorf("fcm client is not present") - continue - } - p := req.Notification.(fcm.Payload) - start := time.Now() - results, err := fc.Send(p) - respTime := time.Now().Sub(start).Seconds() - rs := make([]Result, 0, len(results)) - for _, v := range results { - rs = append(rs, v) - } - sres = SenderResponse{ - Results: rs, - RespTime: respTime, - Req: req, - Err: err, - UID: uuid.NewV4().String(), - } case fcmv1.Payload: if fcv1 == nil { LogWithFields(logrus.Fields{"type": "sender"}). diff --git a/test/gunfish_test.toml b/test/gunfish_test.toml index f4beed3..9724b83 100644 --- a/test/gunfish_test.toml +++ b/test/gunfish_test.toml @@ -1,16 +1,13 @@ [provider] +error_hook = "{{ env `TEST_GUNFISH_HOOK_CMD` `cat ` }}" +max_connections = 2000 +max_request_size = 1000 port = 38103 -worker_num = 8 queue_size = 200 -max_request_size = 1000 -max_connections = 2000 -error_hook = "{{ env `TEST_GUNFISH_HOOK_CMD` `cat ` }}" +worker_num = 8 [apns] -key_file = "{{ env `PROJECT_ROOT` `.` }}/test/server.key" cert_file = "{{ env `PROJECT_ROOT` `.` }}/test/server.crt" -sender_num = 50 +key_file = "{{ env `PROJECT_ROOT` `.` }}/test/server.key" request_per_sec = 2000 - -[fcm] -api_key = 'fcm_test_api_key' +sender_num = 50 diff --git a/test/tools/gunfish-cli/gunfish-cli.go b/test/tools/gunfish-cli/gunfish-cli.go index 0c68153..fe0fb42 100644 --- a/test/tools/gunfish-cli/gunfish-cli.go +++ b/test/tools/gunfish-cli/gunfish-cli.go @@ -6,7 +6,7 @@ import ( "errors" "flag" "fmt" - "io/ioutil" + "io" "log" "net/http" "os" @@ -91,7 +91,7 @@ func run() error { fmt.Println(string(out)) } - out, err := ioutil.ReadFile(jsonFile) + out, err := os.ReadFile(jsonFile) if err != nil { return err } @@ -115,7 +115,7 @@ func run() error { } defer resp.Body.Close() - out, err := ioutil.ReadAll(resp.Body) + out, err := io.ReadAll(resp.Body) if err != nil { return err }