From ea71e99f2d7191dcb008a73630460a06dcf0bd52 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Wed, 4 Aug 2021 09:00:04 +0800 Subject: [PATCH] chore(lint): fix some condition. (#624) --- README.md | 18 ++++++++++++------ notify/notification_apns.go | 2 +- notify/notification_apns_test.go | 2 +- notify/notification_fcm.go | 2 +- notify/notification_hms.go | 2 +- router/server.go | 10 ++-------- router/server_test.go | 5 +++-- rpc/example/go/send/main.go | 9 ++++++--- 8 files changed, 27 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 78fd7e6..d485524 100644 --- a/README.md +++ b/README.md @@ -1070,10 +1070,13 @@ func main() { }, }) if err != nil { - log.Fatalf("could not greet: %v", err) + log.Println("could not greet: ", err) + } + + if r != nil { + log.Printf("Success: %t\n", r.Success) + log.Printf("Count: %d\n", r.Counts) } - log.Printf("Success: %t\n", r.Success) - log.Printf("Count: %d\n", r.Counts) } ``` @@ -1172,10 +1175,13 @@ func main() { }, }) if err != nil { - log.Fatalf("could not greet: %v", err) + log.Println("could not greet: ", err) + } + + if r != nil { + log.Printf("Success: %t\n", r.Success) + log.Printf("Count: %d\n", r.Counts) } - log.Printf("Success: %t\n", r.Success) - log.Printf("Count: %d\n", r.Counts) } ``` diff --git a/notify/notification_apns.go b/notify/notification_apns.go index 96e53f2..5b6c5d3 100644 --- a/notify/notification_apns.go +++ b/notify/notification_apns.go @@ -457,5 +457,5 @@ Retry: goto Retry } - return + return resp, nil } diff --git a/notify/notification_apns_test.go b/notify/notification_apns_test.go index 21b4a61..a69a587 100644 --- a/notify/notification_apns_test.go +++ b/notify/notification_apns_test.go @@ -58,7 +58,7 @@ func TestIOSNotificationStructure(t *testing.T) { test := "test" expectBadge := 0 message := "Welcome notification Server" - expiration := int64(time.Now().Unix()) + expiration := time.Now().Unix() req := &PushNotification{ ApnsID: test, Topic: test, diff --git a/notify/notification_fcm.go b/notify/notification_fcm.go index 501e593..03423bc 100644 --- a/notify/notification_fcm.go +++ b/notify/notification_fcm.go @@ -228,7 +228,7 @@ Retry: goto Retry } - return + return resp, nil } func logPush(cfg *config.ConfYaml, status, token string, req *PushNotification, err error) logx.LogPushEntry { diff --git a/notify/notification_hms.go b/notify/notification_hms.go index f183686..12cf80a 100644 --- a/notify/notification_hms.go +++ b/notify/notification_hms.go @@ -227,5 +227,5 @@ Retry: goto Retry } - return + return resp, nil } diff --git a/router/server.go b/router/server.go index bd3529d..b988d74 100644 --- a/router/server.go +++ b/router/server.go @@ -30,14 +30,7 @@ import ( "golang.org/x/crypto/acme/autocert" ) -var ( - isTerm bool - doOnce sync.Once -) - -func init() { - isTerm = isatty.IsTerminal(os.Stdout.Fd()) -} +var doOnce sync.Once func abortWithError(c *gin.Context, code int, message string) { c.AbortWithStatusJSON(code, gin.H{ @@ -179,6 +172,7 @@ func routerEngine(cfg *config.ConfYaml, q *queue.Queue) *gin.Engine { log.Logger = zerolog.New(os.Stdout).With().Timestamp().Logger() + isTerm := isatty.IsTerminal(os.Stdout.Fd()) if isTerm { log.Logger = log.Output( zerolog.ConsoleWriter{ diff --git a/router/server_test.go b/router/server_test.go index aae869d..d0c68f4 100644 --- a/router/server_test.go +++ b/router/server_test.go @@ -54,12 +54,13 @@ func TestMain(m *testing.M) { queue.WithWorkerCount(4), ) q.Start() + + code := m.Run() defer func() { q.Shutdown() q.Wait() + os.Exit(code) }() - - os.Exit(m.Run()) } func initTest() *config.ConfYaml { diff --git a/rpc/example/go/send/main.go b/rpc/example/go/send/main.go index 9ead8ed..8cf2995 100644 --- a/rpc/example/go/send/main.go +++ b/rpc/example/go/send/main.go @@ -50,8 +50,11 @@ func main() { }, }) if err != nil { - log.Fatalf("could not greet: %v", err) + log.Println("could not greet: ", err) + } + + if r != nil { + log.Printf("Success: %t\n", r.Success) + log.Printf("Count: %d\n", r.Counts) } - log.Printf("Success: %t\n", r.Success) - log.Printf("Count: %d\n", r.Counts) }