From 4ef30a0cdcfe4ab684b12a767df4777634a7a5d9 Mon Sep 17 00:00:00 2001 From: "Bo-Yi.Wu" Date: Tue, 20 Dec 2022 22:03:29 +0800 Subject: [PATCH] fix(lint): warning from golangci-lint tool https://github.com/appleboy/gorush/issues/704 Signed-off-by: Bo-Yi.Wu --- logx/log.go | 1 + logx/log_test.go | 10 +- main.go | 1 + notify/global.go | 5 + notify/notification.go | 34 ++++--- notify/notification_apns.go | 23 +++-- notify/notification_apns_test.go | 164 +++++++++++++++---------------- notify/notification_fcm.go | 2 +- notify/notification_fcm_test.go | 4 +- notify/notification_hms.go | 2 +- notify/notification_test.go | 2 +- router/server.go | 1 + router/server_normal.go | 3 + router/server_test.go | 13 +-- rpc/client_grpc_health.go | 1 + status/status.go | 1 + 16 files changed, 145 insertions(+), 122 deletions(-) diff --git a/logx/log.go b/logx/log.go index f577cb0..176eb7f 100644 --- a/logx/log.go +++ b/logx/log.go @@ -33,6 +33,7 @@ type LogPushEntry struct { var isTerm bool +//nolint func init() { isTerm = isatty.IsTerminal(os.Stdout.Fd()) } diff --git a/logx/log_test.go b/logx/log_test.go index de6d275..c3a65f0 100644 --- a/logx/log_test.go +++ b/logx/log_test.go @@ -11,13 +11,15 @@ import ( "github.com/stretchr/testify/assert" ) +var invalidLevel = "invalid" + func TestSetLogLevel(t *testing.T) { log := logrus.New() err := SetLogLevel(log, "debug") assert.Nil(t, err) - err = SetLogLevel(log, "invalid") + err = SetLogLevel(log, invalidLevel) assert.Equal(t, "not a valid logrus Level: \"invalid\"", err.Error()) } @@ -49,7 +51,7 @@ func TestInitDefaultLog(t *testing.T) { cfg.Log.ErrorLog, )) - cfg.Log.AccessLevel = "invalid" + cfg.Log.AccessLevel = invalidLevel assert.NotNil(t, InitLog( cfg.Log.AccessLevel, @@ -71,7 +73,7 @@ func TestInitDefaultLog(t *testing.T) { func TestAccessLevel(t *testing.T) { cfg, _ := config.LoadConf() - cfg.Log.AccessLevel = "invalid" + cfg.Log.AccessLevel = invalidLevel assert.NotNil(t, InitLog( cfg.Log.AccessLevel, @@ -84,7 +86,7 @@ func TestAccessLevel(t *testing.T) { func TestErrorLevel(t *testing.T) { cfg, _ := config.LoadConf() - cfg.Log.ErrorLevel = "invalid" + cfg.Log.ErrorLevel = invalidLevel assert.NotNil(t, InitLog( cfg.Log.AccessLevel, diff --git a/main.go b/main.go index 2c1618c..eff0af5 100644 --- a/main.go +++ b/main.go @@ -28,6 +28,7 @@ import ( redisdb "github.com/golang-queue/redisdb-stream" ) +//nolint:gocyclo func main() { opts := config.ConfYaml{} diff --git a/notify/global.go b/notify/global.go index 7433be6..19a15a1 100644 --- a/notify/global.go +++ b/notify/global.go @@ -16,3 +16,8 @@ var ( // MaxConcurrentIOSPushes pool to limit the number of concurrent iOS pushes MaxConcurrentIOSPushes chan struct{} ) + +const ( + HIGH = "high" + NORMAL = "nornal" +) diff --git a/notify/notification.go b/notify/notification.go index b2fd3bf..ad40a98 100644 --- a/notify/notification.go +++ b/notify/notification.go @@ -101,22 +101,24 @@ type PushNotification struct { FastAppTarget int `json:"fast_app_target,omitempty"` // iOS - Expiration *int64 `json:"expiration,omitempty"` - ApnsID string `json:"apns_id,omitempty"` - CollapseID string `json:"collapse_id,omitempty"` - Topic string `json:"topic,omitempty"` - PushType string `json:"push_type,omitempty"` - Badge *int `json:"badge,omitempty"` - Category string `json:"category,omitempty"` - ThreadID string `json:"thread-id,omitempty"` - URLArgs []string `json:"url-args,omitempty"` - Alert Alert `json:"alert,omitempty"` - Production bool `json:"production,omitempty"` - Development bool `json:"development,omitempty"` - SoundName string `json:"name,omitempty"` - SoundVolume float32 `json:"volume,omitempty"` - Apns D `json:"apns,omitempty"` - InterruptionLevel string `json:"interruption_level,omitempty"` // ref: https://github.com/sideshow/apns2/blob/54928d6193dfe300b6b88dad72b7e2ae138d4f0a/payload/builder.go#L7-L24 + Expiration *int64 `json:"expiration,omitempty"` + ApnsID string `json:"apns_id,omitempty"` + CollapseID string `json:"collapse_id,omitempty"` + Topic string `json:"topic,omitempty"` + PushType string `json:"push_type,omitempty"` + Badge *int `json:"badge,omitempty"` + Category string `json:"category,omitempty"` + ThreadID string `json:"thread-id,omitempty"` + URLArgs []string `json:"url-args,omitempty"` + Alert Alert `json:"alert,omitempty"` + Production bool `json:"production,omitempty"` + Development bool `json:"development,omitempty"` + SoundName string `json:"name,omitempty"` + SoundVolume float32 `json:"volume,omitempty"` + Apns D `json:"apns,omitempty"` + + // ref: https://github.com/sideshow/apns2/blob/54928d6193dfe300b6b88dad72b7e2ae138d4f0a/payload/builder.go#L7-L24 + InterruptionLevel string `json:"interruption_level,omitempty"` } // Bytes for queue message diff --git a/notify/notification_apns.go b/notify/notification_apns.go index 01c6cf6..6f053e8 100644 --- a/notify/notification_apns.go +++ b/notify/notification_apns.go @@ -30,6 +30,12 @@ var ( tcpKeepAlive = 60 * time.Second ) +const ( + dotP8 = ".p8" + dotPEM = ".pem" + dotP12 = ".p12" +) + var doOnce sync.Once // DialTLS is the default dial function for creating TLS connections for @@ -63,11 +69,11 @@ func InitAPNSClient(cfg *config.ConfYaml) error { ext = filepath.Ext(cfg.Ios.KeyPath) switch ext { - case ".p12": + case dotP12: certificateKey, err = certificate.FromP12File(cfg.Ios.KeyPath, cfg.Ios.Password) - case ".pem": + case dotPEM: certificateKey, err = certificate.FromPemFile(cfg.Ios.KeyPath, cfg.Ios.Password) - case ".p8": + case dotP8: authKey, err = token.AuthKeyFromFile(cfg.Ios.KeyPath) default: err = errors.New("wrong certificate key extension") @@ -87,11 +93,11 @@ func InitAPNSClient(cfg *config.ConfYaml) error { return err } switch ext { - case ".p12": + case dotP12: certificateKey, err = certificate.FromP12Bytes(key, cfg.Ios.Password) - case ".pem": + case dotPEM: certificateKey, err = certificate.FromPemBytes(key, cfg.Ios.Password) - case ".p8": + case dotP8: authKey, err = token.AuthKeyFromBytes(key) default: err = errors.New("wrong certificate key type") @@ -104,7 +110,7 @@ func InitAPNSClient(cfg *config.ConfYaml) error { } } - if ext == ".p8" { + if ext == dotP8 { if cfg.Ios.KeyID == "" || cfg.Ios.TeamID == "" { msg := "you should provide ios.KeyID and ios.TeamID for p8 token" logx.LogError.Error(msg) @@ -154,6 +160,7 @@ func newApnsClient(cfg *config.ConfYaml, certificate tls.Certificate) (*apns2.Cl return client, nil } + //nolint:gosec tlsConfig := &tls.Config{ Certificates: []tls.Certificate{certificate}, } @@ -307,7 +314,7 @@ func GetIOSNotification(req *PushNotification) *apns2.Notification { if len(req.Priority) > 0 { if req.Priority == "normal" { notification.Priority = apns2.PriorityLow - } else if req.Priority == "high" { + } else if req.Priority == HIGH { notification.Priority = apns2.PriorityHigh } } diff --git a/notify/notification_apns_test.go b/notify/notification_apns_test.go index ebb28f8..ea2c5b5 100644 --- a/notify/notification_apns_test.go +++ b/notify/notification_apns_test.go @@ -27,6 +27,13 @@ const ( authkeyValidP8 = `LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1JR0hBZ0VBTUJNR0J5cUdTTTQ5QWdFR0NDcUdTTTQ5QXdFSEJHMHdhd0lCQVFRZ0ViVnpmUG5aUHhmQXl4cUUKWlYwNWxhQW9KQWwrLzZYdDJPNG1PQjYxMXNPaFJBTkNBQVNnRlRLandKQUFVOTVnKysvdnpLV0hrekFWbU5NSQp0QjV2VGpaT09Jd25FYjcwTXNXWkZJeVVGRDFQOUd3c3R6NCtha0hYN3ZJOEJINmhIbUJtZmVRbAotLS0tLUVORCBQUklWQVRFIEtFWS0tLS0tCg==` ) +var ( + testMessage = "test" + testKeyPathP8 = "../certificate/authkey-valid.p8" + testKeyPath = "../certificate/certificate-valid.pem" + welcomeMessage = "Welcome notification Server" +) + func TestDisabledAndroidIosConf(t *testing.T) { cfg, _ := config.LoadConf() cfg.Android.Enabled = false @@ -60,20 +67,19 @@ func TestIOSNotificationStructure(t *testing.T) { var dat map[string]interface{} unix := time.Now().Unix() - test := "test" expectBadge := 0 - message := "Welcome notification Server" + message := welcomeMessage expiration := time.Now().Unix() req := &PushNotification{ - ApnsID: test, - Topic: test, + ApnsID: testMessage, + Topic: testMessage, Expiration: &expiration, Priority: "normal", Message: message, Badge: &expectBadge, Sound: Sound{ Critical: 1, - Name: test, + Name: testMessage, Volume: 1.0, }, ContentAvailable: true, @@ -81,7 +87,7 @@ func TestIOSNotificationStructure(t *testing.T) { "key1": "test", "key2": 2, }, - Category: test, + Category: testMessage, URLArgs: []string{"a", "b"}, } @@ -106,20 +112,20 @@ func TestIOSNotificationStructure(t *testing.T) { aps := dat["aps"].(map[string]interface{}) urlArgs := aps["url-args"].([]interface{}) - assert.Equal(t, test, notification.ApnsID) - assert.Equal(t, test, notification.Topic) + assert.Equal(t, testMessage, notification.ApnsID) + assert.Equal(t, testMessage, notification.Topic) assert.Equal(t, unix, notification.Expiration.Unix()) assert.Equal(t, ApnsPriorityLow, notification.Priority) assert.Equal(t, message, alert) assert.Equal(t, expectBadge, int(badge)) assert.Equal(t, expectBadge, *req.Badge) - assert.Equal(t, test, soundName) + assert.Equal(t, testMessage, soundName) assert.Equal(t, 1.0, soundVolume) assert.Equal(t, int64(1), soundCritical) assert.Equal(t, 1, int(contentAvailable)) assert.Equal(t, "test", key1) assert.Equal(t, 2, int(key2.(float64))) - assert.Equal(t, test, category) + assert.Equal(t, testMessage, category) assert.Contains(t, urlArgs, "a") assert.Contains(t, urlArgs, "b") } @@ -127,16 +133,15 @@ func TestIOSNotificationStructure(t *testing.T) { func TestIOSSoundAndVolume(t *testing.T) { var dat map[string]interface{} - test := "test" - message := "Welcome notification Server" + message := welcomeMessage req := &PushNotification{ - ApnsID: test, - Topic: test, + ApnsID: testMessage, + Topic: testMessage, Priority: "normal", Message: message, Sound: Sound{ Critical: 3, - Name: test, + Name: testMessage, Volume: 4.5, }, } @@ -155,11 +160,11 @@ func TestIOSSoundAndVolume(t *testing.T) { soundCritical, _ := jsonparser.GetInt(data, "aps", "sound", "critical") soundVolume, _ := jsonparser.GetFloat(data, "aps", "sound", "volume") - assert.Equal(t, test, notification.ApnsID) - assert.Equal(t, test, notification.Topic) + assert.Equal(t, testMessage, notification.ApnsID) + assert.Equal(t, testMessage, notification.Topic) assert.Equal(t, ApnsPriorityLow, notification.Priority) assert.Equal(t, message, alert) - assert.Equal(t, test, soundName) + assert.Equal(t, testMessage, soundName) assert.Equal(t, 4.5, soundVolume) assert.Equal(t, int64(3), soundCritical) @@ -181,8 +186,8 @@ func TestIOSSoundAndVolume(t *testing.T) { assert.Equal(t, "foobar", soundName) req = &PushNotification{ - ApnsID: test, - Topic: test, + ApnsID: testMessage, + Topic: testMessage, Priority: "normal", Message: message, Sound: map[string]interface{}{ @@ -208,8 +213,8 @@ func TestIOSSoundAndVolume(t *testing.T) { assert.Equal(t, "test", soundName) req = &PushNotification{ - ApnsID: test, - Topic: test, + ApnsID: testMessage, + Topic: testMessage, Priority: "normal", Message: message, Sound: "default", @@ -230,11 +235,10 @@ func TestIOSSoundAndVolume(t *testing.T) { func TestIOSSummaryArg(t *testing.T) { var dat map[string]interface{} - test := "test" - message := "Welcome notification Server" + message := welcomeMessage req := &PushNotification{ - ApnsID: test, - Topic: test, + ApnsID: testMessage, + Topic: testMessage, Priority: "normal", Message: message, Alert: Alert{ @@ -252,8 +256,8 @@ func TestIOSSummaryArg(t *testing.T) { panic(err) } - assert.Equal(t, test, notification.ApnsID) - assert.Equal(t, test, notification.Topic) + assert.Equal(t, testMessage, notification.ApnsID) + assert.Equal(t, testMessage, notification.Topic) assert.Equal(t, ApnsPriorityLow, notification.Priority) assert.Equal(t, "test", dat["aps"].(map[string]interface{})["alert"].(map[string]interface{})["summary-arg"]) assert.Equal(t, float64(3), dat["aps"].(map[string]interface{})["alert"].(map[string]interface{})["summary-arg-count"]) @@ -264,17 +268,16 @@ func TestIOSSummaryArg(t *testing.T) { func TestSendZeroValueForBadgeKey(t *testing.T) { var dat map[string]interface{} - test := "test" - message := "Welcome notification Server" + message := welcomeMessage req := &PushNotification{ - ApnsID: test, - Topic: test, + ApnsID: testMessage, + Topic: testMessage, Priority: "normal", Message: message, - Sound: test, + Sound: testMessage, ContentAvailable: true, MutableContent: true, - ThreadID: test, + ThreadID: testMessage, } notification := GetIOSNotification(req) @@ -298,13 +301,13 @@ func TestSendZeroValueForBadgeKey(t *testing.T) { t.Errorf("req.Badge must be nil") } - assert.Equal(t, test, notification.ApnsID) - assert.Equal(t, test, notification.Topic) + assert.Equal(t, testMessage, notification.ApnsID) + assert.Equal(t, testMessage, notification.Topic) assert.Equal(t, ApnsPriorityLow, notification.Priority) assert.Equal(t, message, alert) assert.Equal(t, 0, int(badge)) - assert.Equal(t, test, sound) - assert.Equal(t, test, threadID) + assert.Equal(t, testMessage, sound) + assert.Equal(t, testMessage, threadID) assert.Equal(t, 1, int(contentAvailable)) assert.Equal(t, 1, int(mutableContent)) @@ -338,11 +341,10 @@ func TestSendZeroValueForBadgeKey(t *testing.T) { func TestCheckSilentNotification(t *testing.T) { var dat map[string]interface{} - test := "test" req := &PushNotification{ - ApnsID: test, - Topic: test, - CollapseID: test, + ApnsID: testMessage, + Topic: testMessage, + CollapseID: testMessage, Priority: "normal", ContentAvailable: true, } @@ -357,9 +359,9 @@ func TestCheckSilentNotification(t *testing.T) { panic(err) } - assert.Equal(t, test, notification.CollapseID) - assert.Equal(t, test, notification.ApnsID) - assert.Equal(t, test, notification.Topic) + assert.Equal(t, testMessage, notification.CollapseID) + assert.Equal(t, testMessage, notification.ApnsID) + assert.Equal(t, testMessage, notification.Topic) assert.Nil(t, dat["aps"].(map[string]interface{})["alert"]) assert.Nil(t, dat["aps"].(map[string]interface{})["sound"]) assert.Nil(t, dat["aps"].(map[string]interface{})["badge"]) @@ -383,13 +385,12 @@ func TestCheckSilentNotification(t *testing.T) { func TestAlertStringExample2ForIos(t *testing.T) { var dat map[string]interface{} - test := "test" title := "Game Request" body := "Bob wants to play poker" actionLocKey := "PLAY" req := &PushNotification{ - ApnsID: test, - Topic: test, + ApnsID: testMessage, + Topic: testMessage, Priority: "normal", Alert: Alert{ Title: title, @@ -428,15 +429,14 @@ func TestAlertStringExample2ForIos(t *testing.T) { func TestAlertStringExample3ForIos(t *testing.T) { var dat map[string]interface{} - test := "test" badge := 9 sound := "bingbong.aiff" req := &PushNotification{ - ApnsID: test, - Topic: test, + ApnsID: testMessage, + Topic: testMessage, Priority: "normal", ContentAvailable: true, - Message: test, + Message: testMessage, Badge: &badge, Sound: sound, } @@ -453,18 +453,17 @@ func TestAlertStringExample3ForIos(t *testing.T) { assert.Equal(t, sound, dat["aps"].(map[string]interface{})["sound"]) assert.Equal(t, float64(badge), dat["aps"].(map[string]interface{})["badge"].(float64)) - assert.Equal(t, test, dat["aps"].(map[string]interface{})["alert"]) + assert.Equal(t, testMessage, dat["aps"].(map[string]interface{})["alert"]) } func TestMessageAndTitle(t *testing.T) { var dat map[string]interface{} - test := "test" - message := "Welcome notification Server" + message := welcomeMessage title := "Welcome notification Server title" req := &PushNotification{ - ApnsID: test, - Topic: test, + ApnsID: testMessage, + Topic: testMessage, Priority: "normal", Message: message, Title: title, @@ -485,7 +484,7 @@ func TestMessageAndTitle(t *testing.T) { alertBody, _ := jsonparser.GetString(data, "aps", "alert", "body") alertTitle, _ := jsonparser.GetString(data, "aps", "alert", "title") - assert.Equal(t, test, notification.ApnsID) + assert.Equal(t, testMessage, notification.ApnsID) assert.Equal(t, ApnsPriorityLow, notification.Priority) assert.Equal(t, message, alertBody) assert.Equal(t, title, alertTitle) @@ -515,22 +514,21 @@ func TestMessageAndTitle(t *testing.T) { func TestIOSAlertNotificationStructure(t *testing.T) { var dat map[string]interface{} - test := "test" req := &PushNotification{ Message: "Welcome", - Title: test, + Title: testMessage, Alert: Alert{ - Action: test, - ActionLocKey: test, - Body: test, - LaunchImage: test, + Action: testMessage, + ActionLocKey: testMessage, + Body: testMessage, + LaunchImage: testMessage, LocArgs: []string{"a", "b"}, - LocKey: test, - Subtitle: test, + LocKey: testMessage, + Subtitle: testMessage, TitleLocArgs: []string{"a", "b"}, - TitleLocKey: test, + TitleLocKey: testMessage, }, - InterruptionLevel: test, + InterruptionLevel: testMessage, } notification := GetIOSNotification(req) @@ -557,15 +555,15 @@ func TestIOSAlertNotificationStructure(t *testing.T) { titleLocArgs := alert["title-loc-args"].([]interface{}) locArgs := alert["loc-args"].([]interface{}) - assert.Equal(t, test, action) - assert.Equal(t, test, actionLocKey) - assert.Equal(t, test, body) - assert.Equal(t, test, launchImage) - assert.Equal(t, test, locKey) - assert.Equal(t, test, title) - assert.Equal(t, test, subtitle) - assert.Equal(t, test, titleLocKey) - assert.Equal(t, test, interruptionLevel) + assert.Equal(t, testMessage, action) + assert.Equal(t, testMessage, actionLocKey) + assert.Equal(t, testMessage, body) + assert.Equal(t, testMessage, launchImage) + assert.Equal(t, testMessage, locKey) + assert.Equal(t, testMessage, title) + assert.Equal(t, testMessage, subtitle) + assert.Equal(t, testMessage, titleLocKey) + assert.Equal(t, testMessage, interruptionLevel) assert.Contains(t, titleLocArgs, "a") assert.Contains(t, titleLocArgs, "b") assert.Contains(t, locArgs, "a") @@ -613,7 +611,7 @@ func TestAPNSClientProdHost(t *testing.T) { cfg.Ios.Enabled = true cfg.Ios.Production = true - cfg.Ios.KeyPath = "../certificate/certificate-valid.pem" + cfg.Ios.KeyPath = testKeyPath err := InitAPNSClient(cfg) assert.Nil(t, err) assert.Equal(t, apns2.HostProduction, ApnsClient.Host) @@ -642,7 +640,7 @@ func TestAPNSClientInvaildToken(t *testing.T) { // empty key-id or team-id cfg.Ios.Enabled = true - cfg.Ios.KeyPath = "../certificate/authkey-valid.p8" + cfg.Ios.KeyPath = testKeyPathP8 err = InitAPNSClient(cfg) assert.Error(t, err) @@ -661,7 +659,7 @@ func TestAPNSClientVaildToken(t *testing.T) { cfg, _ := config.LoadConf() cfg.Ios.Enabled = true - cfg.Ios.KeyPath = "../certificate/authkey-valid.p8" + cfg.Ios.KeyPath = testKeyPathP8 cfg.Ios.KeyID = "key-id" cfg.Ios.TeamID = "team-id" err := InitAPNSClient(cfg) @@ -706,7 +704,7 @@ func TestAPNSClientUseProxy(t *testing.T) { expectedProxyURL, _ := url.ParseRequestURI(cfg.Core.HTTPProxy) assert.Equal(t, expectedProxyURL, actualProxyURL) - cfg.Ios.KeyPath = "../certificate/authkey-valid.p8" + cfg.Ios.KeyPath = testKeyPathP8 cfg.Ios.TeamID = "example.team" cfg.Ios.KeyID = "example.key" err = InitAPNSClient(cfg) @@ -729,7 +727,7 @@ func TestPushToIOS(t *testing.T) { MaxConcurrentIOSPushes = make(chan struct{}, cfg.Ios.MaxConcurrentPushes) cfg.Ios.Enabled = true - cfg.Ios.KeyPath = "../certificate/certificate-valid.pem" + cfg.Ios.KeyPath = testKeyPath err := InitAPNSClient(cfg) assert.Nil(t, err) err = status.InitAppStatus(cfg) @@ -752,7 +750,7 @@ func TestApnsHostFromRequest(t *testing.T) { cfg, _ := config.LoadConf() cfg.Ios.Enabled = true - cfg.Ios.KeyPath = "../certificate/certificate-valid.pem" + cfg.Ios.KeyPath = testKeyPath err := InitAPNSClient(cfg) assert.Nil(t, err) err = status.InitAppStatus(cfg) diff --git a/notify/notification_fcm.go b/notify/notification_fcm.go index b591365..94948d6 100644 --- a/notify/notification_fcm.go +++ b/notify/notification_fcm.go @@ -52,7 +52,7 @@ func GetAndroidNotification(req *PushNotification) *fcm.Message { notification.RegistrationIDs = req.Tokens } - if req.Priority == "high" || req.Priority == "normal" { + if req.Priority == HIGH || req.Priority == "normal" { notification.Priority = req.Priority } diff --git a/notify/notification_fcm_test.go b/notify/notification_fcm_test.go index f07c337..5d2d547 100644 --- a/notify/notification_fcm_test.go +++ b/notify/notification_fcm_test.go @@ -219,7 +219,7 @@ func TestAndroidNotificationStructure(t *testing.T) { Tokens: []string{"a", "b"}, Message: "Welcome", To: test, - Priority: "high", + Priority: HIGH, CollapseKey: "1", ContentAvailable: true, DelayWhileIdle: true, @@ -242,7 +242,7 @@ func TestAndroidNotificationStructure(t *testing.T) { notification := GetAndroidNotification(req) assert.Equal(t, test, notification.To) - assert.Equal(t, "high", notification.Priority) + assert.Equal(t, HIGH, notification.Priority) assert.Equal(t, "1", notification.CollapseKey) assert.True(t, notification.ContentAvailable) assert.True(t, notification.DelayWhileIdle) diff --git a/notify/notification_hms.go b/notify/notification_hms.go index a7da7a6..dbb2a4b 100644 --- a/notify/notification_hms.go +++ b/notify/notification_hms.go @@ -87,7 +87,7 @@ func GetHuaweiNotification(req *PushNotification) (*model.MessageRequest, error) msgRequest.Message.Condition = req.Condition } - if req.Priority == "high" { + if req.Priority == HIGH { msgRequest.Message.Android.Urgency = "HIGH" } diff --git a/notify/notification_test.go b/notify/notification_test.go index cf81718..c135eab 100644 --- a/notify/notification_test.go +++ b/notify/notification_test.go @@ -15,7 +15,7 @@ func TestCorrectConf(t *testing.T) { cfg.Android.APIKey = "xxxxx" cfg.Ios.Enabled = true - cfg.Ios.KeyPath = "../certificate/certificate-valid.pem" + cfg.Ios.KeyPath = testKeyPath err := CheckPushConf(cfg) diff --git a/router/server.go b/router/server.go index 9642fe0..17e9fb0 100644 --- a/router/server.go +++ b/router/server.go @@ -159,6 +159,7 @@ func autoTLSServer(cfg *config.ConfYaml, q *queue.Queue) *http.Server { Cache: autocert.DirCache(cfg.Core.AutoTLS.Folder), } + //nolint:gosec return &http.Server{ Addr: ":https", TLSConfig: &tls.Config{GetCertificate: m.GetCertificate}, diff --git a/router/server_normal.go b/router/server_normal.go index a7dbe9b..b63c542 100644 --- a/router/server_normal.go +++ b/router/server_normal.go @@ -28,6 +28,7 @@ func RunHTTPServer(ctx context.Context, cfg *config.ConfYaml, q *queue.Queue, s } if len(s) == 0 { + //nolint:gosec server = &http.Server{ Addr: cfg.Core.Address + ":" + cfg.Core.Port, Handler: routerEngine(cfg, q), @@ -40,6 +41,7 @@ func RunHTTPServer(ctx context.Context, cfg *config.ConfYaml, q *queue.Queue, s if cfg.Core.AutoTLS.Enabled { return startServer(ctx, autoTLSServer(cfg, q), cfg) } else if cfg.Core.SSL { + //nolint config := &tls.Config{ MinVersion: tls.VersionTLS10, } @@ -49,6 +51,7 @@ func RunHTTPServer(ctx context.Context, cfg *config.ConfYaml, q *queue.Queue, s } config.Certificates = make([]tls.Certificate, 1) + //nolint:gocritic if cfg.Core.CertPath != "" && cfg.Core.KeyPath != "" { config.Certificates[0], err = tls.LoadX509KeyPair(cfg.Core.CertPath, cfg.Core.KeyPath) if err != nil { diff --git a/router/server_test.go b/router/server_test.go index 9515f69..2e9a43a 100644 --- a/router/server_test.go +++ b/router/server_test.go @@ -26,8 +26,9 @@ import ( ) var ( - goVersion = runtime.Version() - q *queue.Queue + goVersion = runtime.Version() + q *queue.Queue + testKeyPath = "../certificate/certificate-valid.pem" ) func TestMain(m *testing.M) { @@ -471,7 +472,7 @@ func TestSenMultipleNotifications(t *testing.T) { cfg := initTest() cfg.Ios.Enabled = true - cfg.Ios.KeyPath = "../certificate/certificate-valid.pem" + cfg.Ios.KeyPath = testKeyPath err := notify.InitAPNSClient(cfg) assert.Nil(t, err) @@ -507,7 +508,7 @@ func TestDisabledAndroidNotifications(t *testing.T) { cfg := initTest() cfg.Ios.Enabled = true - cfg.Ios.KeyPath = "../certificate/certificate-valid.pem" + cfg.Ios.KeyPath = testKeyPath err := notify.InitAPNSClient(cfg) assert.Nil(t, err) @@ -543,7 +544,7 @@ func TestSyncModeForNotifications(t *testing.T) { cfg := initTest() cfg.Ios.Enabled = true - cfg.Ios.KeyPath = "../certificate/certificate-valid.pem" + cfg.Ios.KeyPath = testKeyPath err := notify.InitAPNSClient(cfg) assert.Nil(t, err) @@ -654,7 +655,7 @@ func TestDisabledIosNotifications(t *testing.T) { cfg := initTest() cfg.Ios.Enabled = false - cfg.Ios.KeyPath = "../certificate/certificate-valid.pem" + cfg.Ios.KeyPath = testKeyPath err := notify.InitAPNSClient(cfg) assert.Nil(t, err) diff --git a/rpc/client_grpc_health.go b/rpc/client_grpc_health.go index 83fa306..30df3d0 100644 --- a/rpc/client_grpc_health.go +++ b/rpc/client_grpc_health.go @@ -43,6 +43,7 @@ func (c *healthClient) Check(ctx context.Context) (bool, error) { } return false, nil } + //nolint:exhaustive switch status.Code(err) { case codes.Aborted, diff --git a/status/status.go b/status/status.go index 96e34aa..7fd28dd 100644 --- a/status/status.go +++ b/status/status.go @@ -58,6 +58,7 @@ func InitAppStatus(conf *config.ConfYaml) error { logx.LogAccess.Info("Init App Status Engine as ", conf.Stat.Engine) var store core.Storage + //nolint:goconst switch conf.Stat.Engine { case "memory": store = memory.New()