fix(lint): update some warning from golangci-lint

https://github.com/appleboy/gorush/issues/704

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi.Wu 2022-12-18 10:06:43 +08:00
parent 577083639c
commit 83a6e63af9
10 changed files with 35 additions and 22 deletions

View File

@ -10,6 +10,7 @@ import (
"github.com/spf13/viper"
)
//nolint
var defaultConf = []byte(`
core:
enabled: true # enable httpd server

View File

@ -153,8 +153,8 @@ func hideToken(token string, markLen int) string {
start := token[len(token)-markLen:]
end := token[0:markLen]
result := strings.Replace(token, start, strings.Repeat("*", markLen), -1)
result = strings.Replace(result, end, strings.Repeat("*", markLen), -1)
result := strings.ReplaceAll(token, start, strings.Repeat("*", markLen))
result = strings.ReplaceAll(result, end, strings.Repeat("*", markLen))
return result
}

View File

@ -2,6 +2,7 @@ package notify
import (
"bytes"
"context"
"errors"
"net"
"net/http"
@ -21,7 +22,7 @@ func DispatchFeedback(log logx.LogPushEntry, url string, timeout int64) error {
return err
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(payload))
req, err := http.NewRequestWithContext(context.Background(), "POST", url, bytes.NewBuffer(payload))
if err != nil {
return err
}

View File

@ -216,17 +216,17 @@ func CheckPushConf(cfg *config.ConfYaml) error {
if cfg.Android.Enabled {
if cfg.Android.APIKey == "" {
return errors.New("Missing Android API Key")
return errors.New("missing android api key")
}
}
if cfg.Huawei.Enabled {
if cfg.Huawei.AppSecret == "" {
return errors.New("Missing Huawei App Secret")
return errors.New("missing huawei app secret")
}
if cfg.Huawei.AppID == "" {
return errors.New("Missing Huawei App ID")
return errors.New("missing huawei app id")
}
}

View File

@ -106,7 +106,7 @@ func InitAPNSClient(cfg *config.ConfYaml) error {
if ext == ".p8" {
if cfg.Ios.KeyID == "" || cfg.Ios.TeamID == "" {
msg := "You should provide ios.KeyID and ios.TeamID for P8 token"
msg := "you should provide ios.KeyID and ios.TeamID for p8 token"
logx.LogError.Error(msg)
return errors.New(msg)
}

View File

@ -1,6 +1,7 @@
package notify
import (
"context"
"log"
"net/http"
"net/url"
@ -698,7 +699,7 @@ func TestAPNSClientUseProxy(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, apns2.HostDevelopment, ApnsClient.Host)
req, _ := http.NewRequest("GET", apns2.HostDevelopment, nil)
req, _ := http.NewRequestWithContext(context.Background(), "GET", apns2.HostDevelopment, nil)
actualProxyURL, err := ApnsClient.HTTPClient.Transport.(*http.Transport).Proxy(req)
assert.Nil(t, err)
@ -713,7 +714,7 @@ func TestAPNSClientUseProxy(t *testing.T) {
assert.Equal(t, apns2.HostDevelopment, ApnsClient.Host)
assert.NotNil(t, ApnsClient.Token)
req, _ = http.NewRequest("GET", apns2.HostDevelopment, nil)
req, _ = http.NewRequestWithContext(context.Background(), "GET", apns2.HostDevelopment, nil)
actualProxyURL, err = ApnsClient.HTTPClient.Transport.(*http.Transport).Proxy(req)
assert.Nil(t, err)

View File

@ -17,7 +17,7 @@ func InitFCMClient(cfg *config.ConfYaml, key string) (*fcm.Client, error) {
var err error
if key == "" && cfg.Android.APIKey == "" {
return nil, errors.New("Missing Android API Key")
return nil, errors.New("missing android api key")
}
if key != "" && key != cfg.Android.APIKey {

View File

@ -38,11 +38,11 @@ func GetPushClient(conf *c.Config) (*client.HMSClient, error) {
// InitHMSClient use for initialize HMS Client.
func InitHMSClient(cfg *config.ConfYaml, appSecret, appID string) (*client.HMSClient, error) {
if appSecret == "" {
return nil, errors.New("Missing Huawei App Secret")
return nil, errors.New("missing huawei app secret")
}
if appID == "" {
return nil, errors.New("Missing Huawei App ID")
return nil, errors.New("missing huawei app id")
}
conf := &c.Config{

View File

@ -222,7 +222,11 @@ func routerEngine(cfg *config.ConfYaml, q *queue.Queue) *gin.Engine {
}
// markFailedNotification adds failure logs for all tokens in push notification
func markFailedNotification(cfg *config.ConfYaml, notification *notify.PushNotification, reason string) []logx.LogPushEntry {
func markFailedNotification(
cfg *config.ConfYaml,
notification *notify.PushNotification,
reason string,
) []logx.LogPushEntry {
logx.LogError.Error(reason)
logs := make([]logx.LogPushEntry, 0)
for _, token := range notification.Tokens {
@ -242,7 +246,12 @@ func markFailedNotification(cfg *config.ConfYaml, notification *notify.PushNotif
}
// HandleNotification add notification to queue list.
func handleNotification(ctx context.Context, cfg *config.ConfYaml, req notify.RequestPush, q *queue.Queue) (int, []logx.LogPushEntry) {
func handleNotification(
ctx context.Context,
cfg *config.ConfYaml,
req notify.RequestPush,
q *queue.Queue,
) (int, []logx.LogPushEntry) {
var count int
wg := sync.WaitGroup{}
newNotification := []*notify.PushNotification{}

View File

@ -68,6 +68,7 @@ func initTest() *config.ConfYaml {
// testRequest is testing url string if server is running
func testRequest(t *testing.T, url string) {
tr := &http.Transport{
//nolint:gosec
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{