diff --git a/core/service/serviceconf.go b/core/service/serviceconf.go index 2bf9a450..04d9283e 100644 --- a/core/service/serviceconf.go +++ b/core/service/serviceconf.go @@ -1,8 +1,6 @@ package service import ( - "log" - "github.com/zeromicro/go-zero/core/load" "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/proc" @@ -39,9 +37,7 @@ type ServiceConf struct { // MustSetUp sets up the service, exits on error. func (sc ServiceConf) MustSetUp() { - if err := sc.SetUp(); err != nil { - log.Fatal(err) - } + logx.Must(sc.SetUp()) } // SetUp sets up the service. diff --git a/core/stores/mon/model.go b/core/stores/mon/model.go index 712bbc9c..e58df7c8 100644 --- a/core/stores/mon/model.go +++ b/core/stores/mon/model.go @@ -2,10 +2,10 @@ package mon import ( "context" - "log" "strings" "github.com/zeromicro/go-zero/core/breaker" + "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/timex" "go.mongodb.org/mongo-driver/mongo" mopt "go.mongodb.org/mongo-driver/mongo/options" @@ -39,10 +39,7 @@ type ( // MustNewModel returns a Model, exits on errors. func MustNewModel(uri, db, collection string, opts ...Option) *Model { model, err := NewModel(uri, db, collection, opts...) - if err != nil { - log.Fatal(err) - } - + logx.Must(err) return model } diff --git a/core/stores/monc/cachedmodel.go b/core/stores/monc/cachedmodel.go index 54deec3b..bab2455e 100644 --- a/core/stores/monc/cachedmodel.go +++ b/core/stores/monc/cachedmodel.go @@ -2,8 +2,8 @@ package monc import ( "context" - "log" + "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/stores/cache" "github.com/zeromicro/go-zero/core/stores/mon" "github.com/zeromicro/go-zero/core/stores/redis" @@ -30,20 +30,14 @@ type Model struct { // MustNewModel returns a Model with a cache cluster, exists on errors. func MustNewModel(uri, db, collection string, c cache.CacheConf, opts ...cache.Option) *Model { model, err := NewModel(uri, db, collection, c, opts...) - if err != nil { - log.Fatal(err) - } - + logx.Must(err) return model } // MustNewNodeModel returns a Model with a cache node, exists on errors. func MustNewNodeModel(uri, db, collection string, rds *redis.Redis, opts ...cache.Option) *Model { model, err := NewNodeModel(uri, db, collection, rds, opts...) - if err != nil { - log.Fatal(err) - } - + logx.Must(err) return model } diff --git a/core/stores/redis/redis.go b/core/stores/redis/redis.go index 2cc0776b..82a44ef3 100644 --- a/core/stores/redis/redis.go +++ b/core/stores/redis/redis.go @@ -4,13 +4,13 @@ import ( "context" "errors" "fmt" - "log" "strconv" "time" red "github.com/go-redis/redis/v8" "github.com/zeromicro/go-zero/core/breaker" "github.com/zeromicro/go-zero/core/errorx" + "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/mapping" "github.com/zeromicro/go-zero/core/syncx" ) @@ -91,22 +91,19 @@ type ( Script = red.Script ) -// New returns a Redis with given options. -// Deprecated: use MustNewRedis or NewRedis instead. -func New(addr string, opts ...Option) *Redis { - return newRedis(addr, opts...) -} - // MustNewRedis returns a Redis with given options. func MustNewRedis(conf RedisConf, opts ...Option) *Redis { rds, err := NewRedis(conf, opts...) - if err != nil { - log.Fatal(err) - } - + logx.Must(err) return rds } +// New returns a Redis with given options. +// Deprecated: use MustNewRedis or NewRedis instead. +func New(addr string, opts ...Option) *Redis { + return newRedis(addr, opts...) +} + // NewRedis returns a Redis with given options. func NewRedis(conf RedisConf, opts ...Option) (*Redis, error) { if err := conf.Validate(); err != nil { diff --git a/rest/handler/contentsecurityhandler_test.go b/rest/handler/contentsecurityhandler_test.go index ada8b194..dfbcc9db 100644 --- a/rest/handler/contentsecurityhandler_test.go +++ b/rest/handler/contentsecurityhandler_test.go @@ -343,7 +343,7 @@ func buildRequest(rs requestSettings) (*http.Request, error) { "time=" + strconv.FormatInt(rs.timestamp, 10), }, "; ") - encrypter, err := codec.NewRsaEncrypter([]byte(pubKey)) + encrypter, err := codec.NewRsaEncrypter(pubKey) if err != nil { log.Fatal(err) } diff --git a/zrpc/client.go b/zrpc/client.go index db00d047..06ff3671 100644 --- a/zrpc/client.go +++ b/zrpc/client.go @@ -1,9 +1,9 @@ package zrpc import ( - "log" "time" + "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/zrpc/internal" "github.com/zeromicro/go-zero/zrpc/internal/auth" "github.com/zeromicro/go-zero/zrpc/internal/clientinterceptors" @@ -43,10 +43,7 @@ type ( // MustNewClient returns a Client, exits on any error. func MustNewClient(c RpcClientConf, options ...ClientOption) Client { cli, err := NewClient(c, options...) - if err != nil { - log.Fatal(err) - } - + logx.Must(err) return cli } diff --git a/zrpc/server.go b/zrpc/server.go index f87e52d5..9cf5a873 100644 --- a/zrpc/server.go +++ b/zrpc/server.go @@ -1,7 +1,6 @@ package zrpc import ( - "log" "time" "github.com/zeromicro/go-zero/core/load" @@ -23,10 +22,7 @@ type RpcServer struct { // MustNewServer returns a RpcSever, exits on any error. func MustNewServer(c RpcServerConf, register internal.RegisterFn) *RpcServer { server, err := NewServer(c, register) - if err != nil { - log.Fatal(err) - } - + logx.Must(err) return server }