chore: remove init if possible (#2485)
This commit is contained in:
@@ -25,9 +25,9 @@ var (
|
|||||||
errValueNotStruct = errors.New("value type is not struct")
|
errValueNotStruct = errors.New("value type is not struct")
|
||||||
keyUnmarshaler = NewUnmarshaler(defaultKeyName)
|
keyUnmarshaler = NewUnmarshaler(defaultKeyName)
|
||||||
durationType = reflect.TypeOf(time.Duration(0))
|
durationType = reflect.TypeOf(time.Duration(0))
|
||||||
cacheKeys map[string][]string
|
cacheKeys = make(map[string][]string)
|
||||||
cacheKeysLock sync.Mutex
|
cacheKeysLock sync.Mutex
|
||||||
defaultCache map[string]interface{}
|
defaultCache = make(map[string]interface{})
|
||||||
defaultCacheLock sync.Mutex
|
defaultCacheLock sync.Mutex
|
||||||
emptyMap = map[string]interface{}{}
|
emptyMap = map[string]interface{}{}
|
||||||
emptyValue = reflect.ValueOf(lang.Placeholder)
|
emptyValue = reflect.ValueOf(lang.Placeholder)
|
||||||
@@ -49,11 +49,6 @@ type (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
cacheKeys = make(map[string][]string)
|
|
||||||
defaultCache = make(map[string]interface{})
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewUnmarshaler returns a Unmarshaler.
|
// NewUnmarshaler returns a Unmarshaler.
|
||||||
func NewUnmarshaler(key string, opts ...UnmarshalOption) *Unmarshaler {
|
func NewUnmarshaler(key string, opts ...UnmarshalOption) *Unmarshaler {
|
||||||
unmarshaler := Unmarshaler{
|
unmarshaler := Unmarshaler{
|
||||||
|
|||||||
@@ -48,4 +48,4 @@ func TestParseHeadersArrayInt(t *testing.T) {
|
|||||||
r.Header.Add("foo", "2")
|
r.Header.Add("foo", "2")
|
||||||
assert.Nil(t, ParseHeaders(r.Header, &val))
|
assert.Nil(t, ParseHeaders(r.Header, &val))
|
||||||
assert.Equal(t, []int{1, 2}, val.Foo)
|
assert.Equal(t, []int{1, 2}, val.Foo)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"google.golang.org/grpc/grpclog"
|
"google.golang.org/grpc/grpclog"
|
||||||
)
|
)
|
||||||
@@ -10,16 +8,11 @@ import (
|
|||||||
// because grpclog.errorLog is not exported, we need to define our own.
|
// because grpclog.errorLog is not exported, we need to define our own.
|
||||||
const errorLevel = 2
|
const errorLevel = 2
|
||||||
|
|
||||||
var once sync.Once
|
|
||||||
|
|
||||||
// A Logger is a rpc logger.
|
// A Logger is a rpc logger.
|
||||||
type Logger struct{}
|
type Logger struct{}
|
||||||
|
|
||||||
// InitLogger initializes the rpc logger.
|
func init() {
|
||||||
func InitLogger() {
|
grpclog.SetLoggerV2(new(Logger))
|
||||||
once.Do(func() {
|
|
||||||
grpclog.SetLoggerV2(new(Logger))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error logs the given args into error log.
|
// Error logs the given args into error log.
|
||||||
|
|||||||
@@ -25,10 +25,6 @@ type (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
InitLogger()
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewRpcServer returns a Server.
|
// NewRpcServer returns a Server.
|
||||||
func NewRpcServer(address string, opts ...ServerOption) Server {
|
func NewRpcServer(address string, opts ...ServerOption) Server {
|
||||||
var options rpcServerOptions
|
var options rpcServerOptions
|
||||||
|
|||||||
Reference in New Issue
Block a user