mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 09:00:20 +08:00
chore: remove any keywords
This commit is contained in:
parent
9e0e01b2bc
commit
2ea0a843f8
@ -17,7 +17,7 @@ const jsonTagKey = "json"
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
fillDefaultUnmarshaler = mapping.NewUnmarshaler(jsonTagKey, mapping.WithDefault())
|
fillDefaultUnmarshaler = mapping.NewUnmarshaler(jsonTagKey, mapping.WithDefault())
|
||||||
loaders = map[string]func([]byte, any) error{
|
loaders = map[string]func([]byte, interface{}) error{
|
||||||
".json": LoadFromJsonBytes,
|
".json": LoadFromJsonBytes,
|
||||||
".toml": LoadFromTomlBytes,
|
".toml": LoadFromTomlBytes,
|
||||||
".yaml": LoadFromYamlBytes,
|
".yaml": LoadFromYamlBytes,
|
||||||
@ -34,8 +34,8 @@ type fieldInfo struct {
|
|||||||
|
|
||||||
// FillDefault fills the default values for the given v,
|
// FillDefault fills the default values for the given v,
|
||||||
// and the premise is that the value of v must be guaranteed to be empty.
|
// and the premise is that the value of v must be guaranteed to be empty.
|
||||||
func FillDefault(v any) error {
|
func FillDefault(v interface{}) error {
|
||||||
return fillDefaultUnmarshaler.Unmarshal(map[string]any{}, v)
|
return fillDefaultUnmarshaler.Unmarshal(map[string]interface{}{}, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load loads config into v from file, .json, .yaml and .yml are acceptable.
|
// Load loads config into v from file, .json, .yaml and .yml are acceptable.
|
||||||
@ -69,13 +69,13 @@ func LoadConfig(file string, v interface{}, opts ...Option) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LoadFromJsonBytes loads config into v from content json bytes.
|
// LoadFromJsonBytes loads config into v from content json bytes.
|
||||||
func LoadFromJsonBytes(content []byte, v any) error {
|
func LoadFromJsonBytes(content []byte, v interface{}) error {
|
||||||
info, err := buildFieldsInfo(reflect.TypeOf(v))
|
info, err := buildFieldsInfo(reflect.TypeOf(v))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var m map[string]any
|
var m map[string]interface{}
|
||||||
if err := jsonx.Unmarshal(content, &m); err != nil {
|
if err := jsonx.Unmarshal(content, &m); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -276,7 +276,7 @@ func toLowerCase(s string) string {
|
|||||||
return strings.ToLower(s)
|
return strings.ToLower(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func toLowerCaseInterface(v any, info *fieldInfo) any {
|
func toLowerCaseInterface(v interface{}, info *fieldInfo) interface{} {
|
||||||
switch vv := v.(type) {
|
switch vv := v.(type) {
|
||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
return toLowerCaseKeyMap(vv, info)
|
return toLowerCaseKeyMap(vv, info)
|
||||||
@ -291,8 +291,8 @@ func toLowerCaseInterface(v any, info *fieldInfo) any {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func toLowerCaseKeyMap(m map[string]any, info *fieldInfo) map[string]any {
|
func toLowerCaseKeyMap(m map[string]interface{}, info *fieldInfo) map[string]interface{} {
|
||||||
res := make(map[string]any)
|
res := make(map[string]interface{})
|
||||||
|
|
||||||
for k, v := range m {
|
for k, v := range m {
|
||||||
ti, ok := info.children[k]
|
ti, ok := info.children[k]
|
||||||
|
@ -632,7 +632,7 @@ func Test_FieldOverwrite(t *testing.T) {
|
|||||||
Name2 *string
|
Name2 *string
|
||||||
}
|
}
|
||||||
|
|
||||||
validate := func(val any) {
|
validate := func(val interface{}) {
|
||||||
input := []byte(`{"Name": "hello", "Name2": "world"}`)
|
input := []byte(`{"Name": "hello", "Name2": "world"}`)
|
||||||
assert.NoError(t, LoadFromJsonBytes(input, val))
|
assert.NoError(t, LoadFromJsonBytes(input, val))
|
||||||
}
|
}
|
||||||
@ -668,7 +668,7 @@ func Test_FieldOverwrite(t *testing.T) {
|
|||||||
Name *string
|
Name *string
|
||||||
}
|
}
|
||||||
|
|
||||||
validate := func(val any) {
|
validate := func(val interface{}) {
|
||||||
input := []byte(`{"Name": "hello"}`)
|
input := []byte(`{"Name": "hello"}`)
|
||||||
err := LoadFromJsonBytes(input, val)
|
err := LoadFromJsonBytes(input, val)
|
||||||
assert.ErrorAs(t, err, &dupErr)
|
assert.ErrorAs(t, err, &dupErr)
|
||||||
@ -711,7 +711,7 @@ func Test_FieldOverwrite(t *testing.T) {
|
|||||||
Name *int
|
Name *int
|
||||||
}
|
}
|
||||||
|
|
||||||
validate := func(val any) {
|
validate := func(val interface{}) {
|
||||||
input := []byte(`{"Name": "hello"}`)
|
input := []byte(`{"Name": "hello"}`)
|
||||||
err := LoadFromJsonBytes(input, val)
|
err := LoadFromJsonBytes(input, val)
|
||||||
assert.ErrorAs(t, err, &dupErr)
|
assert.ErrorAs(t, err, &dupErr)
|
||||||
|
@ -4274,7 +4274,7 @@ func TestUnmarshalOnlyPublicVariables(t *testing.T) {
|
|||||||
Name string `key:"name"`
|
Name string `key:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
m := map[string]any{
|
m := map[string]interface{}{
|
||||||
"age": 3,
|
"age": 3,
|
||||||
"name": "go-zero",
|
"name": "go-zero",
|
||||||
}
|
}
|
||||||
@ -4390,13 +4390,13 @@ func TestFillDefaultUnmarshal(t *testing.T) {
|
|||||||
fillDefaultUnmarshal := NewUnmarshaler(jsonTagKey, WithDefault())
|
fillDefaultUnmarshal := NewUnmarshaler(jsonTagKey, WithDefault())
|
||||||
t.Run("nil", func(t *testing.T) {
|
t.Run("nil", func(t *testing.T) {
|
||||||
type St struct{}
|
type St struct{}
|
||||||
err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, St{})
|
err := fillDefaultUnmarshal.Unmarshal(map[string]interface{}{}, St{})
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("not nil", func(t *testing.T) {
|
t.Run("not nil", func(t *testing.T) {
|
||||||
type St struct{}
|
type St struct{}
|
||||||
err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, &St{})
|
err := fillDefaultUnmarshal.Unmarshal(map[string]interface{}{}, &St{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -4406,7 +4406,7 @@ func TestFillDefaultUnmarshal(t *testing.T) {
|
|||||||
B string
|
B string
|
||||||
}
|
}
|
||||||
var st St
|
var st St
|
||||||
err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, &st)
|
err := fillDefaultUnmarshal.Unmarshal(map[string]interface{}{}, &st)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, st.A, "a")
|
assert.Equal(t, st.A, "a")
|
||||||
})
|
})
|
||||||
@ -4420,7 +4420,7 @@ func TestFillDefaultUnmarshal(t *testing.T) {
|
|||||||
t.Setenv("TEST_C", "c")
|
t.Setenv("TEST_C", "c")
|
||||||
|
|
||||||
var st St
|
var st St
|
||||||
err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, &st)
|
err := fillDefaultUnmarshal.Unmarshal(map[string]interface{}{}, &st)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, st.A, "a")
|
assert.Equal(t, st.A, "a")
|
||||||
assert.Equal(t, st.C, "c")
|
assert.Equal(t, st.C, "c")
|
||||||
@ -4434,7 +4434,7 @@ func TestFillDefaultUnmarshal(t *testing.T) {
|
|||||||
var st = St{
|
var st = St{
|
||||||
A: "b",
|
A: "b",
|
||||||
}
|
}
|
||||||
err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, &st)
|
err := fillDefaultUnmarshal.Unmarshal(map[string]interface{}{}, &st)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
2
core/stores/cache/cachenode_test.go
vendored
2
core/stores/cache/cachenode_test.go
vendored
@ -225,7 +225,7 @@ func TestCacheNode_TakeNotFoundButChangedByOthers(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var str string
|
var str string
|
||||||
err = cn.Take(&str, "any", func(v any) error {
|
err = cn.Take(&str, "any", func(v interface{}) error {
|
||||||
store.Set("any", "foo")
|
store.Set("any", "foo")
|
||||||
return errTestNotFound
|
return errTestNotFound
|
||||||
})
|
})
|
||||||
|
@ -64,7 +64,7 @@ func TestStartAgent(t *testing.T) {
|
|||||||
defer lock.Unlock()
|
defer lock.Unlock()
|
||||||
|
|
||||||
// because remotehost cannot be resolved
|
// because remotehost cannot be resolved
|
||||||
assert.Equal(t, 4, len(agents))
|
assert.Equal(t, 5, len(agents))
|
||||||
_, ok := agents[""]
|
_, ok := agents[""]
|
||||||
assert.True(t, ok)
|
assert.True(t, ok)
|
||||||
_, ok = agents[endpoint1]
|
_, ok = agents[endpoint1]
|
||||||
|
@ -30,7 +30,7 @@ var (
|
|||||||
// Validator defines the interface for validating the request.
|
// Validator defines the interface for validating the request.
|
||||||
type Validator interface {
|
type Validator interface {
|
||||||
// Validate validates the request and parsed data.
|
// Validate validates the request and parsed data.
|
||||||
Validate(r *http.Request, data any) error
|
Validate(r *http.Request, data interface{}) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse parses the request.
|
// Parse parses the request.
|
||||||
|
@ -400,7 +400,7 @@ func BenchmarkParseAuto(b *testing.B) {
|
|||||||
|
|
||||||
type mockValidator struct{}
|
type mockValidator struct{}
|
||||||
|
|
||||||
func (m mockValidator) Validate(r *http.Request, data any) error {
|
func (m mockValidator) Validate(r *http.Request, data interface{}) error {
|
||||||
if r.URL.Path == "/a" {
|
if r.URL.Path == "/a" {
|
||||||
val := reflect.ValueOf(data).Elem().FieldByName("Name").String()
|
val := reflect.ValueOf(data).Elem().FieldByName("Name").String()
|
||||||
if val != "hello" {
|
if val != "hello" {
|
||||||
|
@ -177,7 +177,7 @@ func (v *ApiVisitor) VisitAtHandler(ctx *api.AtHandlerContext) interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// VisitRoute implements from api.BaseApiParserVisitor
|
// VisitRoute implements from api.BaseApiParserVisitor
|
||||||
func (v *ApiVisitor) VisitRoute(ctx *api.RouteContext) any {
|
func (v *ApiVisitor) VisitRoute(ctx *api.RouteContext) interface{} {
|
||||||
var route Route
|
var route Route
|
||||||
path := ctx.Path()
|
path := ctx.Path()
|
||||||
methodExpr := v.newExprWithToken(ctx.GetHttpMethod())
|
methodExpr := v.newExprWithToken(ctx.GetHttpMethod())
|
||||||
|
@ -228,7 +228,7 @@ func (g *Generator) genFunction(goPackage string, serviceName string, service pa
|
|||||||
streamServer = fmt.Sprintf("%s_%s%s", parser.CamelCase(service.Name),
|
streamServer = fmt.Sprintf("%s_%s%s", parser.CamelCase(service.Name),
|
||||||
parser.CamelCase(rpc.Name), "Client")
|
parser.CamelCase(rpc.Name), "Client")
|
||||||
}
|
}
|
||||||
buffer, err := util.With("sharedFn").Parse(text).Execute(map[string]any{
|
buffer, err := util.With("sharedFn").Parse(text).Execute(map[string]interface{}{
|
||||||
"serviceName": serviceName,
|
"serviceName": serviceName,
|
||||||
"rpcServiceName": parser.CamelCase(service.Name),
|
"rpcServiceName": parser.CamelCase(service.Name),
|
||||||
"method": parser.CamelCase(rpc.Name),
|
"method": parser.CamelCase(rpc.Name),
|
||||||
|
Loading…
Reference in New Issue
Block a user