Skip to content

Commit

Permalink
chore: tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
zcong1993 authored and kevwan committed Aug 8, 2024
1 parent 118d707 commit c16e42f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 5 additions & 4 deletions zrpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ func NewServer(c RpcServerConf, register internal.RegisterFn) (*RpcServer, error
metrics.SetName(c.Name)
setupStreamInterceptors(server, c)
setupUnaryInterceptors(server, c, metrics)
if c.Auth {
if err = setupAuthInterceptors(server, c); err != nil {
return nil, err
}
if err = setupAuthInterceptors(server, c); err != nil {
return nil, err
}

rpcServer := &RpcServer{
Expand Down Expand Up @@ -112,6 +110,9 @@ func SetServerSlowThreshold(threshold time.Duration) {
}

func setupAuthInterceptors(svr internal.Server, c RpcServerConf) error {
if !c.Auth {
return nil
}
rds, err := redis.NewRedis(c.Redis.RedisConf)
if err != nil {
return err
Expand Down
9 changes: 9 additions & 0 deletions zrpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,15 @@ func Test_setupStreamInterceptors(t *testing.T) {
}

func Test_setupAuthInterceptors(t *testing.T) {
t.Run("no need set auth", func(t *testing.T) {
s := &mockedServer{}
err := setupAuthInterceptors(s, RpcServerConf{
Auth: false,
Redis: redis.RedisKeyConf{},
})
assert.NoError(t, err)
})

t.Run("redis error", func(t *testing.T) {
s := &mockedServer{}
err := setupAuthInterceptors(s, RpcServerConf{
Expand Down

0 comments on commit c16e42f

Please sign in to comment.