Skip to content

Commit

Permalink
Use interface{} instead of any
Browse files Browse the repository at this point in the history
  • Loading branch information
otiai10 committed Jun 30, 2023
1 parent 8d16417 commit 2cf07c6
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 18 deletions.
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Copyright 2017 otiai10 (Hiromu OCHIAI)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to interface{} person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF interface{} KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR interface{} CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6 changes: 3 additions & 3 deletions all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ func TestRequire(t *testing.T) {
}

func TestTestee_Query(t *testing.T) {
v := map[string]any{
"foo": map[string]any{"name": "otiai10", "age": 30},
"bar": []any{100, "helllo"},
v := map[string]interface{}{
"foo": map[string]interface{}{"name": "otiai10", "age": 30},
"bar": []interface{}{100, "helllo"},
}
mint.Expect(t, "foo").Query("foo").ToBe("foo")
mint.Expect(t, "foo").Query("bar").Not().ToBe("bar")
Expand Down
1 change: 1 addition & 0 deletions exit_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !freebsd
// +build !freebsd

package mint_test
Expand Down
6 changes: 3 additions & 3 deletions mquery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ mquery
```go
import mquery

var m = map[string]any{
var m = map[string]interface{}{
"foo": "bar",
"hoge": map[string]any{
"hoge": map[string]interface{}{
"name": "otiai10",
},
"fuga": map[int]map[string]any{
"fuga": map[int]map[string]interface{}{
0: {"greet": "Hello"},
1: {"greet": "こんにちは"},
},
Expand Down
6 changes: 3 additions & 3 deletions mquery/all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"testing"
)

var m = map[string]any{
var m = map[string]interface{}{
"foo": "bar",
"hoge": map[string]any{
"hoge": map[string]interface{}{
"name": "otiai10",
},
"fuga": map[int]map[string]any{
"fuga": map[int]map[string]interface{}{
0: {"greet": "Hello"},
1: {"greet": "こんにちは"},
},
Expand Down
6 changes: 3 additions & 3 deletions mquery/example_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package mquery

var a = map[string]any{
var a = map[string]interface{}{
"foo": "bar",
"hoge": map[string]any{
"hoge": map[string]interface{}{
"name": "otiai10",
},
"fuga": map[int]map[string]any{
"fuga": map[int]map[string]interface{}{
0: {"greet": "Hello"},
1: {"greet": "こんにちは"},
},
Expand Down
8 changes: 4 additions & 4 deletions mquery/mquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"strings"
)

func Query(m any, q string) any {
func Query(m interface{}, q string) interface{} {
return query(m, strings.Split(q, "."))
}

func query(m any, qs []string) any {
func query(m interface{}, qs []string) interface{} {
t := reflect.TypeOf(m)
switch t.Kind() {
case reflect.Map:
Expand All @@ -23,7 +23,7 @@ func query(m any, qs []string) any {
}
}

func queryMap(m any, t reflect.Type, qs []string) any {
func queryMap(m interface{}, t reflect.Type, qs []string) interface{} {
if len(qs) == 0 {
return m
}
Expand Down Expand Up @@ -52,7 +52,7 @@ func queryMap(m any, t reflect.Type, qs []string) any {
return nil
}

func querySlice(m any, t reflect.Type, qs []string) any {
func querySlice(m interface{}, t reflect.Type, qs []string) interface{} {
if len(qs) == 0 {
return m
}
Expand Down

0 comments on commit 2cf07c6

Please sign in to comment.