Skip to content

Commit

Permalink
chore: remove any keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan committed Mar 4, 2023
1 parent 9e0e01b commit 2ea0a84
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 23 deletions.
16 changes: 8 additions & 8 deletions core/conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand All @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions core/conf/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions core/mapping/unmarshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Expand Down Expand Up @@ -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)
})

Expand All @@ -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")
})
Expand All @@ -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")
Expand All @@ -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 changes: 1 addition & 1 deletion core/stores/cache/cachenode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
2 changes: 1 addition & 1 deletion core/trace/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion rest/httpx/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion rest/httpx/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion tools/goctl/api/parser/g4/ast/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion tools/goctl/rpc/generator/gencall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 2ea0a84

Please sign in to comment.