chore: use logx.Must instead of log.Fatal (#3189)

master
Kevin Wan 2 years ago committed by GitHub
parent a31256b327
commit 8ffe4c01d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,8 +1,6 @@
package service package service
import ( import (
"log"
"github.com/zeromicro/go-zero/core/load" "github.com/zeromicro/go-zero/core/load"
"github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/core/proc" "github.com/zeromicro/go-zero/core/proc"
@ -39,9 +37,7 @@ type ServiceConf struct {
// MustSetUp sets up the service, exits on error. // MustSetUp sets up the service, exits on error.
func (sc ServiceConf) MustSetUp() { func (sc ServiceConf) MustSetUp() {
if err := sc.SetUp(); err != nil { logx.Must(sc.SetUp())
log.Fatal(err)
}
} }
// SetUp sets up the service. // SetUp sets up the service.

@ -2,10 +2,10 @@ package mon
import ( import (
"context" "context"
"log"
"strings" "strings"
"github.com/zeromicro/go-zero/core/breaker" "github.com/zeromicro/go-zero/core/breaker"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/core/timex" "github.com/zeromicro/go-zero/core/timex"
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"
mopt "go.mongodb.org/mongo-driver/mongo/options" mopt "go.mongodb.org/mongo-driver/mongo/options"
@ -39,10 +39,7 @@ type (
// MustNewModel returns a Model, exits on errors. // MustNewModel returns a Model, exits on errors.
func MustNewModel(uri, db, collection string, opts ...Option) *Model { func MustNewModel(uri, db, collection string, opts ...Option) *Model {
model, err := NewModel(uri, db, collection, opts...) model, err := NewModel(uri, db, collection, opts...)
if err != nil { logx.Must(err)
log.Fatal(err)
}
return model return model
} }

@ -2,8 +2,8 @@ package monc
import ( import (
"context" "context"
"log"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/core/stores/cache" "github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/mon" "github.com/zeromicro/go-zero/core/stores/mon"
"github.com/zeromicro/go-zero/core/stores/redis" "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. // MustNewModel returns a Model with a cache cluster, exists on errors.
func MustNewModel(uri, db, collection string, c cache.CacheConf, opts ...cache.Option) *Model { func MustNewModel(uri, db, collection string, c cache.CacheConf, opts ...cache.Option) *Model {
model, err := NewModel(uri, db, collection, c, opts...) model, err := NewModel(uri, db, collection, c, opts...)
if err != nil { logx.Must(err)
log.Fatal(err)
}
return model return model
} }
// MustNewNodeModel returns a Model with a cache node, exists on errors. // MustNewNodeModel returns a Model with a cache node, exists on errors.
func MustNewNodeModel(uri, db, collection string, rds *redis.Redis, opts ...cache.Option) *Model { func MustNewNodeModel(uri, db, collection string, rds *redis.Redis, opts ...cache.Option) *Model {
model, err := NewNodeModel(uri, db, collection, rds, opts...) model, err := NewNodeModel(uri, db, collection, rds, opts...)
if err != nil { logx.Must(err)
log.Fatal(err)
}
return model return model
} }

@ -4,13 +4,13 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"log"
"strconv" "strconv"
"time" "time"
red "github.com/go-redis/redis/v8" red "github.com/go-redis/redis/v8"
"github.com/zeromicro/go-zero/core/breaker" "github.com/zeromicro/go-zero/core/breaker"
"github.com/zeromicro/go-zero/core/errorx" "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/mapping"
"github.com/zeromicro/go-zero/core/syncx" "github.com/zeromicro/go-zero/core/syncx"
) )
@ -91,22 +91,19 @@ type (
Script = red.Script 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. // MustNewRedis returns a Redis with given options.
func MustNewRedis(conf RedisConf, opts ...Option) *Redis { func MustNewRedis(conf RedisConf, opts ...Option) *Redis {
rds, err := NewRedis(conf, opts...) rds, err := NewRedis(conf, opts...)
if err != nil { logx.Must(err)
log.Fatal(err)
}
return rds 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. // NewRedis returns a Redis with given options.
func NewRedis(conf RedisConf, opts ...Option) (*Redis, error) { func NewRedis(conf RedisConf, opts ...Option) (*Redis, error) {
if err := conf.Validate(); err != nil { if err := conf.Validate(); err != nil {

@ -343,7 +343,7 @@ func buildRequest(rs requestSettings) (*http.Request, error) {
"time=" + strconv.FormatInt(rs.timestamp, 10), "time=" + strconv.FormatInt(rs.timestamp, 10),
}, "; ") }, "; ")
encrypter, err := codec.NewRsaEncrypter([]byte(pubKey)) encrypter, err := codec.NewRsaEncrypter(pubKey)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

@ -1,9 +1,9 @@
package zrpc package zrpc
import ( import (
"log"
"time" "time"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/zrpc/internal" "github.com/zeromicro/go-zero/zrpc/internal"
"github.com/zeromicro/go-zero/zrpc/internal/auth" "github.com/zeromicro/go-zero/zrpc/internal/auth"
"github.com/zeromicro/go-zero/zrpc/internal/clientinterceptors" "github.com/zeromicro/go-zero/zrpc/internal/clientinterceptors"
@ -43,10 +43,7 @@ type (
// MustNewClient returns a Client, exits on any error. // MustNewClient returns a Client, exits on any error.
func MustNewClient(c RpcClientConf, options ...ClientOption) Client { func MustNewClient(c RpcClientConf, options ...ClientOption) Client {
cli, err := NewClient(c, options...) cli, err := NewClient(c, options...)
if err != nil { logx.Must(err)
log.Fatal(err)
}
return cli return cli
} }

@ -1,7 +1,6 @@
package zrpc package zrpc
import ( import (
"log"
"time" "time"
"github.com/zeromicro/go-zero/core/load" "github.com/zeromicro/go-zero/core/load"
@ -23,10 +22,7 @@ type RpcServer struct {
// MustNewServer returns a RpcSever, exits on any error. // MustNewServer returns a RpcSever, exits on any error.
func MustNewServer(c RpcServerConf, register internal.RegisterFn) *RpcServer { func MustNewServer(c RpcServerConf, register internal.RegisterFn) *RpcServer {
server, err := NewServer(c, register) server, err := NewServer(c, register)
if err != nil { logx.Must(err)
log.Fatal(err)
}
return server return server
} }

Loading…
Cancel
Save