mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 00:50:20 +08:00
chore: remove any keywords
This commit is contained in:
parent
9e0e01b2bc
commit
2ea0a843f8
@ -17,7 +17,7 @@ const jsonTagKey = "json"
|
||||
|
||||
var (
|
||||
fillDefaultUnmarshaler = mapping.NewUnmarshaler(jsonTagKey, mapping.WithDefault())
|
||||
loaders = map[string]func([]byte, any) error{
|
||||
loaders = map[string]func([]byte, interface{}) error{
|
||||
".json": LoadFromJsonBytes,
|
||||
".toml": LoadFromTomlBytes,
|
||||
".yaml": LoadFromYamlBytes,
|
||||
@ -34,8 +34,8 @@ type fieldInfo struct {
|
||||
|
||||
// FillDefault fills the default values for the given v,
|
||||
// and the premise is that the value of v must be guaranteed to be empty.
|
||||
func FillDefault(v any) error {
|
||||
return fillDefaultUnmarshaler.Unmarshal(map[string]any{}, v)
|
||||
func FillDefault(v interface{}) error {
|
||||
return fillDefaultUnmarshaler.Unmarshal(map[string]interface{}{}, v)
|
||||
}
|
||||
|
||||
// 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.
|
||||
func LoadFromJsonBytes(content []byte, v any) error {
|
||||
func LoadFromJsonBytes(content []byte, v interface{}) error {
|
||||
info, err := buildFieldsInfo(reflect.TypeOf(v))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var m map[string]any
|
||||
var m map[string]interface{}
|
||||
if err := jsonx.Unmarshal(content, &m); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -276,7 +276,7 @@ func toLowerCase(s string) string {
|
||||
return strings.ToLower(s)
|
||||
}
|
||||
|
||||
func toLowerCaseInterface(v any, info *fieldInfo) any {
|
||||
func toLowerCaseInterface(v interface{}, info *fieldInfo) interface{} {
|
||||
switch vv := v.(type) {
|
||||
case map[string]interface{}:
|
||||
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 {
|
||||
res := make(map[string]any)
|
||||
func toLowerCaseKeyMap(m map[string]interface{}, info *fieldInfo) map[string]interface{} {
|
||||
res := make(map[string]interface{})
|
||||
|
||||
for k, v := range m {
|
||||
ti, ok := info.children[k]
|
||||
|
@ -632,7 +632,7 @@ func Test_FieldOverwrite(t *testing.T) {
|
||||
Name2 *string
|
||||
}
|
||||
|
||||
validate := func(val any) {
|
||||
validate := func(val interface{}) {
|
||||
input := []byte(`{"Name": "hello", "Name2": "world"}`)
|
||||
assert.NoError(t, LoadFromJsonBytes(input, val))
|
||||
}
|
||||
@ -668,7 +668,7 @@ func Test_FieldOverwrite(t *testing.T) {
|
||||
Name *string
|
||||
}
|
||||
|
||||
validate := func(val any) {
|
||||
validate := func(val interface{}) {
|
||||
input := []byte(`{"Name": "hello"}`)
|
||||
err := LoadFromJsonBytes(input, val)
|
||||
assert.ErrorAs(t, err, &dupErr)
|
||||
@ -711,7 +711,7 @@ func Test_FieldOverwrite(t *testing.T) {
|
||||
Name *int
|
||||
}
|
||||
|
||||
validate := func(val any) {
|
||||
validate := func(val interface{}) {
|
||||
input := []byte(`{"Name": "hello"}`)
|
||||
err := LoadFromJsonBytes(input, val)
|
||||
assert.ErrorAs(t, err, &dupErr)
|
||||
|
@ -4274,7 +4274,7 @@ func TestUnmarshalOnlyPublicVariables(t *testing.T) {
|
||||
Name string `key:"name"`
|
||||
}
|
||||
|
||||
m := map[string]any{
|
||||
m := map[string]interface{}{
|
||||
"age": 3,
|
||||
"name": "go-zero",
|
||||
}
|
||||
@ -4390,13 +4390,13 @@ func TestFillDefaultUnmarshal(t *testing.T) {
|
||||
fillDefaultUnmarshal := NewUnmarshaler(jsonTagKey, WithDefault())
|
||||
t.Run("nil", func(t *testing.T) {
|
||||
type St struct{}
|
||||
err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, St{})
|
||||
err := fillDefaultUnmarshal.Unmarshal(map[string]interface{}{}, St{})
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("not nil", func(t *testing.T) {
|
||||
type St struct{}
|
||||
err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, &St{})
|
||||
err := fillDefaultUnmarshal.Unmarshal(map[string]interface{}{}, &St{})
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
@ -4406,7 +4406,7 @@ func TestFillDefaultUnmarshal(t *testing.T) {
|
||||
B string
|
||||
}
|
||||
var st St
|
||||
err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, &st)
|
||||
err := fillDefaultUnmarshal.Unmarshal(map[string]interface{}{}, &st)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, st.A, "a")
|
||||
})
|
||||
@ -4420,7 +4420,7 @@ func TestFillDefaultUnmarshal(t *testing.T) {
|
||||
t.Setenv("TEST_C", "c")
|
||||
|
||||
var st St
|
||||
err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, &st)
|
||||
err := fillDefaultUnmarshal.Unmarshal(map[string]interface{}{}, &st)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, st.A, "a")
|
||||
assert.Equal(t, st.C, "c")
|
||||
@ -4434,7 +4434,7 @@ func TestFillDefaultUnmarshal(t *testing.T) {
|
||||
var st = St{
|
||||
A: "b",
|
||||
}
|
||||
err := fillDefaultUnmarshal.Unmarshal(map[string]any{}, &st)
|
||||
err := fillDefaultUnmarshal.Unmarshal(map[string]interface{}{}, &st)
|
||||
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
|
||||
err = cn.Take(&str, "any", func(v any) error {
|
||||
err = cn.Take(&str, "any", func(v interface{}) error {
|
||||
store.Set("any", "foo")
|
||||
return errTestNotFound
|
||||
})
|
||||
|
@ -64,7 +64,7 @@ func TestStartAgent(t *testing.T) {
|
||||
defer lock.Unlock()
|
||||
|
||||
// because remotehost cannot be resolved
|
||||
assert.Equal(t, 4, len(agents))
|
||||
assert.Equal(t, 5, len(agents))
|
||||
_, ok := agents[""]
|
||||
assert.True(t, ok)
|
||||
_, ok = agents[endpoint1]
|
||||
|
@ -30,7 +30,7 @@ var (
|
||||
// Validator defines the interface for validating the request.
|
||||
type Validator interface {
|
||||
// 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.
|
||||
|
@ -400,7 +400,7 @@ func BenchmarkParseAuto(b *testing.B) {
|
||||
|
||||
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" {
|
||||
val := reflect.ValueOf(data).Elem().FieldByName("Name").String()
|
||||
if val != "hello" {
|
||||
|
@ -177,7 +177,7 @@ func (v *ApiVisitor) VisitAtHandler(ctx *api.AtHandlerContext) interface{} {
|
||||
}
|
||||
|
||||
// VisitRoute implements from api.BaseApiParserVisitor
|
||||
func (v *ApiVisitor) VisitRoute(ctx *api.RouteContext) any {
|
||||
func (v *ApiVisitor) VisitRoute(ctx *api.RouteContext) interface{} {
|
||||
var route Route
|
||||
path := ctx.Path()
|
||||
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),
|
||||
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,
|
||||
"rpcServiceName": parser.CamelCase(service.Name),
|
||||
"method": parser.CamelCase(rpc.Name),
|
||||
|
Loading…
Reference in New Issue
Block a user