diff --git a/config/config.go b/config/config.go index 3fa5997..7210c7c 100644 --- a/config/config.go +++ b/config/config.go @@ -253,7 +253,6 @@ func LoadConf(confPath string) (ConfYaml, error) { if confPath != "" { content, err := ioutil.ReadFile(confPath) - if err != nil { return conf, err } diff --git a/gorush/feedback.go b/gorush/feedback.go index c891257..0eb2557 100644 --- a/gorush/feedback.go +++ b/gorush/feedback.go @@ -11,13 +11,11 @@ import ( // DispatchFeedback sends a feedback to the configured gateway. func DispatchFeedback(log LogPushEntry, url string, timeout int64) error { - if url == "" { return errors.New("The url can't be empty") } payload, err := json.Marshal(log) - if err != nil { return err } @@ -29,13 +27,13 @@ func DispatchFeedback(log LogPushEntry, url string, timeout int64) error { req.Header.Set("Content-Type", "application/json; charset=utf-8") - var transport = &http.Transport{ + transport := &http.Transport{ Dial: (&net.Dialer{ Timeout: 5 * time.Second, }).Dial, TLSHandshakeTimeout: 5 * time.Second, } - var client = &http.Client{ + client := &http.Client{ Timeout: time.Duration(timeout) * time.Second, Transport: transport, } diff --git a/gorush/feedback_test.go b/gorush/feedback_test.go index 1a67708..4a3ebd8 100644 --- a/gorush/feedback_test.go +++ b/gorush/feedback_test.go @@ -43,14 +43,12 @@ func TestHTTPErrorInFeedbackCall(t *testing.T) { } func TestSuccessfulFeedbackCall(t *testing.T) { - // Mock http server httpMock := httptest.NewServer( http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/dispatch" { w.Header().Add("Content-Type", "application/json") _, err := w.Write([]byte(`{}`)) - if err != nil { log.Println(err) panic(err) diff --git a/gorush/log.go b/gorush/log.go index 76fcbcb..e0f3a2e 100644 --- a/gorush/log.go +++ b/gorush/log.go @@ -40,7 +40,6 @@ func init() { // InitLog use for initial log module func InitLog() error { - var err error // init logger @@ -90,8 +89,7 @@ func SetLogOut(log *logrus.Logger, outString string) error { case "stderr": log.Out = os.Stderr default: - f, err := os.OpenFile(outString, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600) - + f, err := os.OpenFile(outString, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o600) if err != nil { return err } @@ -106,7 +104,6 @@ func SetLogOut(log *logrus.Logger, outString string) error { // log level: panic, fatal, error, warn, info and debug func SetLogLevel(log *logrus.Logger, levelString string) error { level, err := logrus.ParseLevel(levelString) - if err != nil { return err } diff --git a/gorush/metrics.go b/gorush/metrics.go index 71a9f2a..058c021 100644 --- a/gorush/metrics.go +++ b/gorush/metrics.go @@ -21,7 +21,6 @@ type Metrics struct { // NewMetrics returns a new Metrics with all prometheus.Desc initialized func NewMetrics() Metrics { - return Metrics{ TotalPushCount: prometheus.NewDesc( namespace+"total_push_count", diff --git a/gorush/notification.go b/gorush/notification.go index edd4fb1..a1eeff5 100644 --- a/gorush/notification.go +++ b/gorush/notification.go @@ -131,7 +131,6 @@ func (p *PushNotification) AddLog(log LogPushEntry) { // IsTopic check if message format is topic for FCM // ref: https://firebase.google.com/docs/cloud-messaging/send-message#topic-http-post-request func (p *PushNotification) IsTopic() bool { - if p.Platform == PlatFormAndroid { return p.To != "" && strings.HasPrefix(p.To, "/topics/") || p.Condition != "" } @@ -185,9 +184,7 @@ func CheckMessage(req PushNotification) error { // SetProxy only working for FCM server. func SetProxy(proxy string) error { - proxyURL, err := url.ParseRequestURI(proxy) - if err != nil { return err } diff --git a/gorush/notification_apns.go b/gorush/notification_apns.go index 13aa71d..23a1bae 100644 --- a/gorush/notification_apns.go +++ b/gorush/notification_apns.go @@ -377,9 +377,7 @@ func PushToIOS(req PushNotification) { } Retry: - var ( - newTokens []string - ) + var newTokens []string notification := GetIOSNotification(req) client := getApnsClient(req) diff --git a/gorush/notification_apns_test.go b/gorush/notification_apns_test.go index 91ebb8d..e000133 100644 --- a/gorush/notification_apns_test.go +++ b/gorush/notification_apns_test.go @@ -52,9 +52,10 @@ func TestMissingIOSCertificate(t *testing.T) { assert.Error(t, err) assert.Equal(t, "certificate file does not exist", err.Error()) } + func TestIOSNotificationStructure(t *testing.T) { var dat map[string]interface{} - var unix = time.Now().Unix() + unix := time.Now().Unix() test := "test" expectBadge := 0 @@ -579,7 +580,7 @@ func TestDisabledIosNotifications(t *testing.T) { req := RequestPush{ Notifications: []PushNotification{ - //ios + // ios { Tokens: []string{"11aa01229f15f0f0c52029d8cf8cd0aeaf2365fe4cebc4af26cd6d76b7919ef7"}, Platform: PlatFormIos, @@ -667,7 +668,7 @@ func TestAPNSClientInvaildToken(t *testing.T) { err = InitAPNSClient() assert.Error(t, err) - //empty key-id or team-id + // empty key-id or team-id PushConf.Ios.Enabled = true PushConf.Ios.KeyPath = "../certificate/authkey-valid.p8" err = InitAPNSClient() diff --git a/gorush/notification_fcm.go b/gorush/notification_fcm.go index 8a3d155..de1129c 100644 --- a/gorush/notification_fcm.go +++ b/gorush/notification_fcm.go @@ -116,7 +116,6 @@ func PushToAndroid(req PushNotification) { // check message err := CheckMessage(req) - if err != nil { LogError.Error("request error: " + err.Error()) return diff --git a/gorush/notification_fcm_test.go b/gorush/notification_fcm_test.go index 530ef26..b9106e8 100644 --- a/gorush/notification_fcm_test.go +++ b/gorush/notification_fcm_test.go @@ -39,6 +39,7 @@ func TestMissingAndroidAPIKey(t *testing.T) { assert.Error(t, err) assert.Equal(t, "Missing Android API Key", err.Error()) } + func TestMissingKeyForInitFCMClient(t *testing.T) { client, err := InitFCMClient("") @@ -220,7 +221,6 @@ func TestCheckAndroidMessage(t *testing.T) { } func TestAndroidNotificationStructure(t *testing.T) { - test := "test" timeToLive := uint(100) req := PushNotification{ diff --git a/gorush/notification_hms.go b/gorush/notification_hms.go index 9a26412..933b853 100644 --- a/gorush/notification_hms.go +++ b/gorush/notification_hms.go @@ -33,7 +33,6 @@ func GetPushClient(conf *config.Config) (*core.HMSClient, error) { // InitHMSClient use for initialize HMS Client. func InitHMSClient(apiKey string, appID string) (*core.HMSClient, error) { - if apiKey == "" { return nil, errors.New("Missing Huawei API Key") } @@ -42,7 +41,7 @@ func InitHMSClient(apiKey string, appID string) (*core.HMSClient, error) { return nil, errors.New("Missing Huawei APP Id") } - var conf = &config.Config{ + conf := &config.Config{ AppId: appID, AppSecret: apiKey, AuthUrl: "https://login.cloud.huawei.com/oauth2/v2/token", @@ -64,7 +63,6 @@ func InitHMSClient(apiKey string, appID string) (*core.HMSClient, error) { // HTTP Connection Server Reference for HMS // https://developer.huawei.com/consumer/en/doc/development/HMS-References/push-sendapi func GetHuaweiNotification(req PushNotification) (*model.MessageRequest, error) { - msgRequest := model.NewNotificationMsgRequest() msgRequest.Message.Android = model.GetDefaultAndroid() @@ -89,7 +87,7 @@ func GetHuaweiNotification(req PushNotification) (*model.MessageRequest, error) msgRequest.Message.Android.Urgency = "HIGH" } - //if req.HuaweiCollapseKey != nil { + // if req.HuaweiCollapseKey != nil { msgRequest.Message.Android.CollapseKey = req.HuaweiCollapseKey //} @@ -107,11 +105,11 @@ func GetHuaweiNotification(req PushNotification) (*model.MessageRequest, error) msgRequest.Message.Android.FastAppTarget = req.FastAppTarget - //Add data fields + // Add data fields if len(req.HuaweiData) > 0 { msgRequest.Message.Data = req.HuaweiData } else { - //Notification Message + // Notification Message msgRequest.Message.Android.Notification = model.GetDefaultAndroidNotification() n := msgRequest.Message.Android.Notification @@ -179,14 +177,13 @@ func PushToHuawei(req PushNotification) bool { // check message err := CheckMessage(req) - if err != nil { LogError.Error("request error: " + err.Error()) return false } Retry: - var isError = false + isError := false notification, _ := GetHuaweiNotification(req) diff --git a/gorush/notification_test.go b/gorush/notification_test.go index c7b41ca..ca0ff9c 100644 --- a/gorush/notification_test.go +++ b/gorush/notification_test.go @@ -39,7 +39,7 @@ func TestSenMultipleNotifications(t *testing.T) { req := RequestPush{ Notifications: []PushNotification{ - //ios + // ios { Tokens: []string{"11aa01229f15f0f0c52029d8cf8cd0aeaf2365fe4cebc4af26cd6d76b7919ef7"}, Platform: PlatFormIos, @@ -75,7 +75,7 @@ func TestDisabledAndroidNotifications(t *testing.T) { req := RequestPush{ Notifications: []PushNotification{ - //ios + // ios { Tokens: []string{"11aa01229f15f0f0c52029d8cf8cd0aeaf2365fe4cebc4af26cd6d76b7919ef7"}, Platform: PlatFormIos, @@ -114,7 +114,7 @@ func TestSyncModeForNotifications(t *testing.T) { req := RequestPush{ Notifications: []PushNotification{ - //ios + // ios { Tokens: []string{"11aa01229f15f0f0c52029d8cf8cd0aeaf2365fe4cebc4af26cd6d76b7919ef7"}, Platform: PlatFormIos, @@ -205,7 +205,6 @@ func TestSyncModeForDeviceGroupNotification(t *testing.T) { } func TestSetProxyURL(t *testing.T) { - err := SetProxy("87.236.233.92:8080") assert.Error(t, err) assert.Equal(t, "parse \"87.236.233.92:8080\": invalid URI for request", err.Error()) diff --git a/gorush/server.go b/gorush/server.go index c659767..952f8e5 100644 --- a/gorush/server.go +++ b/gorush/server.go @@ -19,9 +19,7 @@ import ( "golang.org/x/crypto/acme/autocert" ) -var ( - rxURL = regexp.MustCompile(`^/healthz$`) -) +var rxURL = regexp.MustCompile(`^/healthz$`) func init() { // Support metrics diff --git a/gorush/server_test.go b/gorush/server_test.go index f186d93..b2769b9 100644 --- a/gorush/server_test.go +++ b/gorush/server_test.go @@ -92,8 +92,8 @@ func TestRunTLSServer(t *testing.T) { } func TestRunTLSBase64Server(t *testing.T) { - var cert = `LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUMrekNDQWVPZ0F3SUJBZ0lKQUxiWkVEdlVRckZLTUEwR0NTcUdTSWIzRFFFQkJRVUFNQlF4RWpBUUJnTlYKQkFNTUNXeHZZMkZzYUc5emREQWVGdzB4TmpBek1qZ3dNek13TkRGYUZ3MHlOakF6TWpZd016TXdOREZhTUJReApFakFRQmdOVkJBTU1DV3h2WTJGc2FHOXpkRENDQVNJd0RRWUpLb1pJaHZjTkFRRUJCUUFEZ2dFUEFEQ0NBUW9DCmdnRUJBTWoxK3hnNGpWTHpWbkI1ajduMXVsMzBXRUU0QkN6Y05GeGc1QU9CNUg1cSt3amUwWVlpVkZnNlBReXYKR0NpcHFJUlhWUmRWUTFoSFN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Z3lJYm01UjlaTjFnV1djNDdvRndMVjNyeFdxWGdzNmZtZzhjWAo3djMwOXZGY0M5UTQvVnhhYTRCNUxOSzluM2dUQUlCUFRPdGxVbmwrMm15MXRmQnRCcVJtMFc2SUtiVEhXUzVnCnZ4akVtL0NpRUl5R1VFZ3FUTWdIQVFLQmdCS3VYZFFvdXRuZzYzUXVmd0l6RHRiS1Z6TUxRNFhpTktobWJYcGgKT2F2Q25wK2dQYkIrTDdZbDhsdEFtVFNPSmdWWjBoY1QwRHhBMzYxWngrMk11NThHQmw0T2JsbmNobXdFMXZqMQpLY1F5UHJFUXhkb1VUeWlzd0dmcXZyczhKOWltdmIrejkvVTZUMUtBQjhXaTNXVmlYelByNE1zaWFhUlhnNjQyCkZJZHhBb0dBWjcvNzM1ZGtoSmN5T2ZzK0xLc0xyNjhKU3N0b29yWE9ZdmRNdTErSkdhOWlMdWhuSEVjTVZXQzgKSXVpaHpQZmxvWnRNYkdZa1pKbjhsM0JlR2Q4aG1mRnRnVGdaR1BvVlJldGZ0MkxERkxuUHhwMnNFSDVPRkxzUQpSK0sva0FPdWw4ZVN0V3VNWE9GQTlwTXpHa0dFZ0lGSk1KT3lhSk9OM2tlZFFJOGRlQ009Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg==` initTest() PushConf.Core.SSL = true @@ -224,7 +224,6 @@ func TestMissingNotificationsParameter(t *testing.T) { // missing notifications parameter. r.POST("/api/push"). Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { - assert.Equal(t, http.StatusBadRequest, r.Code) assert.Equal(t, "application/json; charset=utf-8", r.HeaderMap.Get("Content-Type")) }) @@ -241,7 +240,6 @@ func TestEmptyNotifications(t *testing.T) { "notifications": []PushNotification{}, }). Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { - assert.Equal(t, http.StatusBadRequest, r.Code) }) } @@ -299,7 +297,6 @@ func TestOutOfRangeMaxNotifications(t *testing.T) { }, }). Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { - assert.Equal(t, http.StatusBadRequest, r.Code) }) } @@ -326,7 +323,6 @@ func TestSuccessPushHandler(t *testing.T) { }, }). Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { - assert.Equal(t, http.StatusOK, r.Code) }) } @@ -391,6 +387,7 @@ func TestVersionHandler(t *testing.T) { assert.Equal(t, "3.0.0", value) }) } + func TestDisabledHTTPServer(t *testing.T) { initTest() PushConf.Core.Enabled = false diff --git a/main.go b/main.go index 9cd8cdc..1f6b356 100644 --- a/main.go +++ b/main.go @@ -201,7 +201,6 @@ func main() { } err := gorush.CheckMessage(req) - if err != nil { gorush.LogError.Fatal(err) } @@ -235,7 +234,6 @@ func main() { } err := gorush.CheckMessage(req) - if err != nil { gorush.LogError.Fatal(err) } @@ -273,7 +271,6 @@ func main() { } err := gorush.CheckMessage(req) - if err != nil { gorush.LogError.Fatal(err) } @@ -415,13 +412,13 @@ func usage() { // handles pinging the endpoint and returns an error if the // agent is in an unhealthy state. func pinger() error { - var transport = &http.Transport{ + transport := &http.Transport{ Dial: (&net.Dialer{ Timeout: 5 * time.Second, }).Dial, TLSHandshakeTimeout: 5 * time.Second, } - var client = &http.Client{ + client := &http.Client{ Timeout: time.Second * 10, Transport: transport, } diff --git a/rpc/proto/gorush.pb.go b/rpc/proto/gorush.pb.go index 6b402b4..24392f1 100644 --- a/rpc/proto/gorush.pb.go +++ b/rpc/proto/gorush.pb.go @@ -8,6 +8,9 @@ package proto import ( context "context" + reflect "reflect" + sync "sync" + proto "github.com/golang/protobuf/proto" _struct "github.com/golang/protobuf/ptypes/struct" grpc "google.golang.org/grpc" @@ -15,8 +18,6 @@ import ( status "google.golang.org/grpc/status" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" ) const ( @@ -659,18 +660,21 @@ func file_gorush_proto_rawDescGZIP() []byte { return file_gorush_proto_rawDescData } -var file_gorush_proto_enumTypes = make([]protoimpl.EnumInfo, 2) -var file_gorush_proto_msgTypes = make([]protoimpl.MessageInfo, 5) -var file_gorush_proto_goTypes = []interface{}{ - (Priority)(0), // 0: proto.Priority - (HealthCheckResponse_ServingStatus)(0), // 1: proto.HealthCheckResponse.ServingStatus - (*Alert)(nil), // 2: proto.Alert - (*NotificationRequest)(nil), // 3: proto.NotificationRequest - (*NotificationReply)(nil), // 4: proto.NotificationReply - (*HealthCheckRequest)(nil), // 5: proto.HealthCheckRequest - (*HealthCheckResponse)(nil), // 6: proto.HealthCheckResponse - (*_struct.Struct)(nil), // 7: google.protobuf.Struct -} +var ( + file_gorush_proto_enumTypes = make([]protoimpl.EnumInfo, 2) + file_gorush_proto_msgTypes = make([]protoimpl.MessageInfo, 5) + file_gorush_proto_goTypes = []interface{}{ + (Priority)(0), // 0: proto.Priority + (HealthCheckResponse_ServingStatus)(0), // 1: proto.HealthCheckResponse.ServingStatus + (*Alert)(nil), // 2: proto.Alert + (*NotificationRequest)(nil), // 3: proto.NotificationRequest + (*NotificationReply)(nil), // 4: proto.NotificationReply + (*HealthCheckRequest)(nil), // 5: proto.HealthCheckRequest + (*HealthCheckResponse)(nil), // 6: proto.HealthCheckResponse + (*_struct.Struct)(nil), // 7: google.protobuf.Struct + } +) + var file_gorush_proto_depIdxs = []int32{ 2, // 0: proto.NotificationRequest.alert:type_name -> proto.Alert 7, // 1: proto.NotificationRequest.data:type_name -> google.protobuf.Struct @@ -776,8 +780,10 @@ func file_gorush_proto_init() { } // Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConnInterface +var ( + _ context.Context + _ grpc.ClientConnInterface +) // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. @@ -813,8 +819,7 @@ type GorushServer interface { } // UnimplementedGorushServer can be embedded to have forward compatible implementations. -type UnimplementedGorushServer struct { -} +type UnimplementedGorushServer struct{} func (*UnimplementedGorushServer) Send(context.Context, *NotificationRequest) (*NotificationReply, error) { return nil, status.Errorf(codes.Unimplemented, "method Send not implemented") @@ -885,8 +890,7 @@ type HealthServer interface { } // UnimplementedHealthServer can be embedded to have forward compatible implementations. -type UnimplementedHealthServer struct { -} +type UnimplementedHealthServer struct{} func (*UnimplementedHealthServer) Check(context.Context, *HealthCheckRequest) (*HealthCheckResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Check not implemented") diff --git a/rpc/server.go b/rpc/server.go index 4a43c96..e6b6b8e 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -49,7 +49,7 @@ func (s *Server) Check(ctx context.Context, in *proto.HealthCheckRequest) (*prot // Send implements helloworld.GreeterServer func (s *Server) Send(ctx context.Context, in *proto.NotificationRequest) (*proto.NotificationReply, error) { - var badge = int(in.Badge) + badge := int(in.Badge) notification := gorush.PushNotification{ Platform: int(in.Platform), Tokens: in.Tokens, diff --git a/storage/badger/badger.go b/storage/badger/badger.go index b017d69..b0dcd3a 100644 --- a/storage/badger/badger.go +++ b/storage/badger/badger.go @@ -68,7 +68,6 @@ func (s *Storage) setBadger(key string, count int64) { value := convert.ToString(count).(string) return txn.Set([]byte(key), []byte(value)) }) - if err != nil { log.Println(s.name, "update error:", err.Error()) } @@ -95,7 +94,6 @@ func (s *Storage) getBadger(key string, count *int64) { return nil }) - if err != nil { log.Println(s.name, "get error:", err.Error()) } diff --git a/storage/buntdb/buntdb.go b/storage/buntdb/buntdb.go index 0dda8cd..b09c0bb 100644 --- a/storage/buntdb/buntdb.go +++ b/storage/buntdb/buntdb.go @@ -58,7 +58,6 @@ func (s *Storage) setBuntDB(key string, count int64) { } return nil }) - if err != nil { log.Println("BuntDB update error:", err.Error()) } @@ -70,7 +69,6 @@ func (s *Storage) getBuntDB(key string, count *int64) { *count, _ = strconv.ParseInt(val, 10, 64) return nil }) - if err != nil { log.Println("BuntDB get error:", err.Error()) }