fix: error from golangci-lint tool (#623)

This commit is contained in:
Bo-Yi Wu
2021-08-03 14:44:00 +08:00
committed by GitHub
parent 349c0c8c1d
commit 0a8d801380
15 changed files with 74 additions and 164 deletions

View File

@@ -284,7 +284,7 @@ func handleNotification(ctx context.Context, cfg *config.ConfYaml, req notify.Re
if core.IsLocalQueue(core.Queue(cfg.Queue.Engine)) && cfg.Core.Sync {
func(msg *notify.PushNotification, cfg *config.ConfYaml) {
q.QueueTask(func(ctx context.Context) error {
if err := q.QueueTask(func(ctx context.Context) error {
defer wg.Done()
resp, err := notify.SendNotification(msg, cfg)
if err != nil {
@@ -292,19 +292,17 @@ func handleNotification(ctx context.Context, cfg *config.ConfYaml, req notify.Re
}
// add log
for _, v := range resp.Logs {
logs = append(logs, v)
}
logs = append(logs, resp.Logs...)
return nil
})
}); err != nil {
logx.LogError.Error(err)
}
}(notification, cfg)
} else if err := q.Queue(notification); err != nil {
resp := markFailedNotification(cfg, notification, "max capacity reached")
// add log
for _, v := range resp {
logs = append(logs, v)
}
logs = append(logs, resp...)
wg.Done()
}

View File

@@ -82,13 +82,11 @@ func RunHTTPServer(ctx context.Context, cfg *config.ConfYaml, q *queue.Queue, s
func listenAndServe(ctx context.Context, s *http.Server, cfg *config.ConfYaml) error {
var g errgroup.Group
g.Go(func() error {
select {
case <-ctx.Done():
timeout := time.Duration(cfg.Core.ShutdownTimeout) * time.Second
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
return s.Shutdown(ctx)
}
<-ctx.Done()
timeout := time.Duration(cfg.Core.ShutdownTimeout) * time.Second
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
return s.Shutdown(ctx)
})
g.Go(func() error {
if err := s.ListenAndServe(); err != nil && err != http.ErrServerClosed {
@@ -102,13 +100,11 @@ func listenAndServe(ctx context.Context, s *http.Server, cfg *config.ConfYaml) e
func listenAndServeTLS(ctx context.Context, s *http.Server, cfg *config.ConfYaml) error {
var g errgroup.Group
g.Go(func() error {
select {
case <-ctx.Done():
timeout := time.Duration(cfg.Core.ShutdownTimeout) * time.Second
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
return s.Shutdown(ctx)
}
<-ctx.Done()
timeout := time.Duration(cfg.Core.ShutdownTimeout) * time.Second
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
return s.Shutdown(ctx)
})
g.Go(func() error {
if err := s.ListenAndServeTLS("", ""); err != nil && err != http.ErrServerClosed {

View File

@@ -59,7 +59,7 @@ func TestMain(m *testing.M) {
q.Wait()
}()
m.Run()
os.Exit(m.Run())
}
func initTest() *config.ConfYaml {
@@ -232,7 +232,6 @@ func TestRootHandler(t *testing.T) {
assert.Equal(t, "Welcome to notification server.", value)
assert.Equal(t, http.StatusOK, r.Code)
assert.Equal(t, "application/json; charset=utf-8", r.HeaderMap.Get("Content-Type"))
})
}
@@ -291,7 +290,6 @@ func TestMissingNotificationsParameter(t *testing.T) {
r.POST("/api/push").
Run(routerEngine(cfg, q), 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"))
})
}