all: gofmt -w -r 'interface{} -> any' (#2874)

This commit is contained in:
Ariel Mashraki
2022-08-19 18:23:04 +03:00
committed by GitHub
parent b6c185a660
commit 2c63d1d70e
619 changed files with 3449 additions and 3449 deletions

View File

@@ -72,6 +72,6 @@ func (c Client) Query(ctx context.Context, query string) (*Response, error) {
}
// Queryf formats a query string and invokes Query.
func (c Client) Queryf(ctx context.Context, format string, args ...interface{}) (*Response, error) {
func (c Client) Queryf(ctx context.Context, format string, args ...any) (*Response, error) {
return c.Query(ctx, fmt.Sprintf(format, args...))
}

View File

@@ -149,6 +149,6 @@ func TestExpandOrdering(t *testing.T) {
}
c, err := cfg.Build(WithInterceptor(interceptor))
require.NoError(t, err)
req := NewEvalRequest("g.V().hasLabel($1)", WithBindings(map[string]interface{}{"$1": "user"}))
req := NewEvalRequest("g.V().hasLabel($1)", WithBindings(map[string]any{"$1": "user"}))
_, _ = c.Do(context.Background(), req)
}

View File

@@ -27,14 +27,14 @@ func NewDriver(c *Client) *Driver {
func (Driver) Dialect() string { return dialect.Gremlin }
// Exec implements the dialect.Exec method.
func (c *Driver) Exec(ctx context.Context, query string, args, v interface{}) error {
func (c *Driver) Exec(ctx context.Context, query string, args, v any) error {
vr, ok := v.(*Response)
if !ok {
return fmt.Errorf("dialect/gremlin: invalid type %T. expect *gremlin.Response", v)
}
bindings, ok := args.(dsl.Bindings)
if !ok {
return fmt.Errorf("dialect/gremlin: invalid type %T. expect map[string]interface{} for bindings", args)
return fmt.Errorf("dialect/gremlin: invalid type %T. expect map[string]any for bindings", args)
}
res, err := c.Do(ctx, NewEvalRequest(query, WithBindings(bindings)))
if err != nil {
@@ -45,7 +45,7 @@ func (c *Driver) Exec(ctx context.Context, query string, args, v interface{}) er
}
// Query implements the dialect.Query method.
func (c *Driver) Query(ctx context.Context, query string, args, v interface{}) error {
func (c *Driver) Query(ctx context.Context, query string, args, v any) error {
return c.Exec(ctx, query, args, v)
}

View File

@@ -66,7 +66,7 @@ func BenchmarkMarshalInterface(b *testing.B) {
b.Fatal(err)
}
var obj interface{}
var obj any
if err = jsoniter.Unmarshal(data, &obj); err != nil {
b.Fatal(err)
}
@@ -87,7 +87,7 @@ func BenchmarkUnmarshalInterface(b *testing.B) {
b.Fatal(err)
}
var obj interface{}
var obj any
b.ResetTimer()
for n := 0; n < b.N; n++ {

View File

@@ -18,19 +18,19 @@ type decodeExtension struct {
// Unmarshal parses the graphson encoded data and stores the result
// in the value pointed to by v.
func Unmarshal(data []byte, v interface{}) error {
func Unmarshal(data []byte, v any) error {
return config.Unmarshal(data, v)
}
// UnmarshalFromString parses the graphson encoded str and stores the result
// in the value pointed to by v.
func UnmarshalFromString(str string, v interface{}) error {
func UnmarshalFromString(str string, v any) error {
return config.UnmarshalFromString(str, v)
}
// Decoder defines a graphson decoder.
type Decoder interface {
Decode(interface{}) error
Decode(any) error
}
// NewDecoder create a graphson decoder.

View File

@@ -17,18 +17,18 @@ type encodeExtension struct {
}
// Marshal returns the graphson encoding of v.
func Marshal(v interface{}) ([]byte, error) {
func Marshal(v any) ([]byte, error) {
return config.Marshal(v)
}
// MarshalToString returns the graphson encoding of v as string.
func MarshalToString(v interface{}) (string, error) {
func MarshalToString(v any) (string, error) {
return config.MarshalToString(v)
}
// Encoder defines a graphson encoder.
type Encoder interface {
Encode(interface{}) error
Encode(any) error
}
// NewEncoder create a graphson encoder.

View File

@@ -12,16 +12,16 @@ import (
)
// EncoderOfError returns a value encoder which always fails to encode.
func (encodeExtension) EncoderOfError(format string, args ...interface{}) jsoniter.ValEncoder {
func (encodeExtension) EncoderOfError(format string, args ...any) jsoniter.ValEncoder {
return decoratorOfError(format, args...)
}
// DecoderOfError returns a value decoder which always fails to decode.
func (decodeExtension) DecoderOfError(format string, args ...interface{}) jsoniter.ValDecoder {
func (decodeExtension) DecoderOfError(format string, args ...any) jsoniter.ValDecoder {
return decoratorOfError(format, args...)
}
func decoratorOfError(format string, args ...interface{}) errorCodec {
func decoratorOfError(format string, args ...any) errorCodec {
err := fmt.Errorf(format, args...)
return errorCodec{err}
}

View File

@@ -55,7 +55,7 @@ func (dec efaceDecoder) decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) {
it := config.BorrowIterator(data)
defer config.ReturnIterator(it)
var val interface{}
var val any
if rtype != nil {
val = rtype.New()
it.ReadVal(val)
@@ -120,13 +120,13 @@ func (efaceDecoder) reflectType(typ Type) reflect2.Type {
}
func (efaceDecoder) reflectSlice(data []byte) (reflect2.Type, error) {
var elem interface{}
if err := Unmarshal(data, &[...]*interface{}{&elem}); err != nil {
var elem any
if err := Unmarshal(data, &[...]*any{&elem}); err != nil {
return nil, fmt.Errorf("cannot read first list element: %w", err)
}
if elem == nil {
return reflect2.TypeOf([]interface{}{}), nil
return reflect2.TypeOf([]any{}), nil
}
sliceType := reflect.SliceOf(reflect.TypeOf(elem))
@@ -134,16 +134,16 @@ func (efaceDecoder) reflectSlice(data []byte) (reflect2.Type, error) {
}
func (efaceDecoder) reflectMap(data []byte) (reflect2.Type, error) {
var key, elem interface{}
var key, elem any
if err := Unmarshal(
bytes.Replace(data, []byte(mapType), []byte(listType), 1),
&[...]*interface{}{&key, &elem},
&[...]*any{&key, &elem},
); err != nil {
return nil, fmt.Errorf("cannot unmarshal first map item: %w", err)
}
if key == nil {
return reflect2.TypeOf(map[interface{}]interface{}{}), nil
return reflect2.TypeOf(map[any]any{}), nil
} else if elem == nil {
return nil, errors.New("expect map element, but found only key")
}

View File

@@ -16,7 +16,7 @@ func TestDecodeInterface(t *testing.T) {
tests := []struct {
name string
in string
want interface{}
want any
wantErr bool
}{
{
@@ -155,7 +155,7 @@ func TestDecodeInterface(t *testing.T) {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
var got interface{}
var got any
err := UnmarshalFromString(tc.in, &got)
if !tc.wantErr {
require.NoError(t, err)
@@ -170,14 +170,14 @@ func TestDecodeInterface(t *testing.T) {
func TestDecodeInterfaceSlice(t *testing.T) {
tests := []struct {
in string
want interface{}
want any
}{
{
in: `{
"@type": "g:List",
"@value": []
}`,
want: []interface{}{},
want: []any{},
},
{
in: `{
@@ -219,7 +219,7 @@ func TestDecodeInterfaceSlice(t *testing.T) {
tc := tc
t.Run(fmt.Sprintf("%T", tc.want), func(t *testing.T) {
t.Parallel()
var got interface{}
var got any
err := UnmarshalFromString(tc.in, &got)
require.NoError(t, err)
assert.Equal(t, tc.want, got)
@@ -230,14 +230,14 @@ func TestDecodeInterfaceSlice(t *testing.T) {
func TestDecodeInterfaceMap(t *testing.T) {
tests := []struct {
in string
want interface{}
want any
}{
{
in: `{
"@type": "g:Map",
"@value": []
}`,
want: map[interface{}]interface{}{},
want: map[any]any{},
},
{
in: `{
@@ -314,7 +314,7 @@ func TestDecodeInterfaceMap(t *testing.T) {
tc := tc
t.Run(fmt.Sprintf("%T", tc.want), func(t *testing.T) {
t.Parallel()
var got interface{}
var got any
err := UnmarshalFromString(tc.in, &got)
require.NoError(t, err)
assert.Equal(t, tc.want, got)
@@ -339,11 +339,11 @@ func TestDecodeInterfaceObject(t *testing.T) {
data, err := Marshal(book)
require.NoError(t, err)
var v interface{}
var v any
err = Unmarshal(data, &v)
require.NoError(t, err)
obj := v.(map[string]interface{})
obj := v.(map[string]any)
assert.Equal(t, book.ID, obj["id"])
assert.Equal(t, book.Title, obj["title"])
assert.Equal(t, book.Author, obj["author"])

View File

@@ -17,7 +17,7 @@ import (
func TestEncodeMap(t *testing.T) {
tests := []struct {
name string
in interface{}
in any
want string
}{
{
@@ -47,7 +47,7 @@ func TestEncodeMap(t *testing.T) {
},
{
name: "mixed",
in: map[string]interface{}{
in: map[string]any{
"byte": byte('a'),
"string": "str",
"slice": []int{1, 2, 3},
@@ -119,11 +119,11 @@ func TestEncodeMap(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, "g:Map", jsoniter.Get(data, "@type").ToString())
var want []interface{}
var want []any
err = jsoniter.UnmarshalFromString(tc.want, &want)
require.NoError(t, err)
got, ok := jsoniter.Get(data, "@value").GetInterface().([]interface{})
got, ok := jsoniter.Get(data, "@value").GetInterface().([]any)
require.True(t, ok)
assert.ElementsMatch(t, want, got)
})
@@ -134,7 +134,7 @@ func TestDecodeMap(t *testing.T) {
tests := []struct {
name string
in string
want interface{}
want any
}{
{
name: "empty",

View File

@@ -23,7 +23,7 @@ func TestMarshalerEncode(t *testing.T) {
call := m.On("MarshalGraphson").Return(want, nil)
defer m.AssertExpectations(t)
tests := []interface{}{m, &m, func() *Marshaler { marshaler := Marshaler(m); return &marshaler }(), Marshaler(nil)}
tests := []any{m, &m, func() *Marshaler { marshaler := Marshaler(m); return &marshaler }(), Marshaler(nil)}
call.Times(len(tests) - 1)
for _, tc := range tests {

View File

@@ -17,7 +17,7 @@ import (
func TestEncodeNative(t *testing.T) {
tests := []struct {
in interface{}
in any
want string
wantErr bool
}{
@@ -142,7 +142,7 @@ func TestEncodeNative(t *testing.T) {
}`,
},
{
in: func() interface{} { v := int16(6116); return &v }(),
in: func() any { v := int16(6116); return &v }(),
want: `{
"@type": "gx:Int16",
"@value": 6116
@@ -177,7 +177,7 @@ func TestEncodeNative(t *testing.T) {
func TestDecodeNative(t *testing.T) {
tests := []struct {
in string
want interface{}
want any
}{
{
in: `{"@type": "g:Float", "@value": 3.14}`,

View File

@@ -25,7 +25,7 @@ func TestEncodeArray(t *testing.T) {
func TestEncodeSlice(t *testing.T) {
tests := []struct {
in interface{}
in any
want string
}{
{
@@ -95,7 +95,7 @@ func TestEncodeSlice(t *testing.T) {
func TestDecodeSlice(t *testing.T) {
tests := []struct {
in string
want interface{}
want any
}{
{
in: `{
@@ -170,7 +170,7 @@ func TestDecodeBadSlice(t *testing.T) {
tests := []struct {
name string
in string
new func() interface{}
new func() any
}{
{
name: "TypeMismatch",
@@ -187,7 +187,7 @@ func TestDecodeBadSlice(t *testing.T) {
}
]
}`,
new: func() interface{} { return &[]int{} },
new: func() any { return &[]int{} },
},
{
name: "BadValue",
@@ -204,7 +204,7 @@ func TestDecodeBadSlice(t *testing.T) {
}
]
}`,
new: func() interface{} { return &[2]int{} },
new: func() any { return &[2]int{} },
},
}

View File

@@ -15,7 +15,7 @@ import (
func TestEncodeStruct(t *testing.T) {
tests := []struct {
name string
in interface{}
in any
want string
}{
{
@@ -108,7 +108,7 @@ func TestDecodeStruct(t *testing.T) {
tests := []struct {
name string
in string
want interface{}
want any
}{
{
name: "Simple",

View File

@@ -16,7 +16,7 @@ func TestTimeEncoding(t *testing.T) {
const ms = 1481750076295
ts := time.Unix(0, ms*time.Millisecond.Nanoseconds())
for _, v := range []interface{}{ts, &ts} {
for _, v := range []any{ts, &ts} {
got, err := MarshalToString(v)
require.NoError(t, err)
assert.JSONEq(t, `{ "@type": "g:Timestamp", "@value": 1481750076295 }`, got)

View File

@@ -65,7 +65,7 @@ func TestEncodeTyper(t *testing.T) {
}
}`
for _, tc := range []interface{}{m, &m, v, vv, &vv} {
for _, tc := range []any{m, &m, v, vv, &vv} {
got, err := MarshalToString(tc)
assert.NoError(t, err)
assert.JSONEq(t, want, got)

View File

@@ -25,7 +25,7 @@ func ExpandBindings(rt RoundTripper) RoundTripper {
return rt.RoundTrip(ctx, r)
}
{
query, bindings := query.(string), bindings.(map[string]interface{})
query, bindings := query.(string), bindings.(map[string]any)
keys := make(sort.StringSlice, 0, len(bindings))
for k := range bindings {
keys = append(keys, k)

View File

@@ -23,27 +23,27 @@ func TestExpandBindings(t *testing.T) {
wantQuery: "no bindings",
},
{
req: NewEvalRequest("g.V($0)", WithBindings(map[string]interface{}{"$0": 1})),
req: NewEvalRequest("g.V($0)", WithBindings(map[string]any{"$0": 1})),
wantQuery: "g.V(1)",
},
{
req: NewEvalRequest("g.V().has($1, $2)", WithBindings(map[string]interface{}{"$1": "name", "$2": "a8m"})),
req: NewEvalRequest("g.V().has($1, $2)", WithBindings(map[string]any{"$1": "name", "$2": "a8m"})),
wantQuery: "g.V().has(\"name\", \"a8m\")",
},
{
req: NewEvalRequest("g.V().limit(n)", WithBindings(map[string]interface{}{"n": 10})),
req: NewEvalRequest("g.V().limit(n)", WithBindings(map[string]any{"n": 10})),
wantQuery: "g.V().limit(10)",
},
{
req: NewEvalRequest("g.V()", WithBindings(map[string]interface{}{"$0": func() {}})),
req: NewEvalRequest("g.V()", WithBindings(map[string]any{"$0": func() {}})),
wantErr: true,
},
{
req: NewEvalRequest("g.V().has($0, $1)", WithBindings(map[string]interface{}{"$0": "active", "$1": true})),
req: NewEvalRequest("g.V().has($0, $1)", WithBindings(map[string]any{"$0": "active", "$1": true})),
wantQuery: "g.V().has(\"active\", true)",
},
{
req: NewEvalRequest("g.V().has($1, $11)", WithBindings(map[string]interface{}{"$1": "active", "$11": true})),
req: NewEvalRequest("g.V().has($1, $11)", WithBindings(map[string]any{"$1": "active", "$11": true})),
wantQuery: "g.V().has(\"active\", true)",
},
}
@@ -64,8 +64,8 @@ func TestExpandBindingsNoQuery(t *testing.T) {
rt := ExpandBindings(RoundTripperFunc(func(ctx context.Context, r *Request) (*Response, error) {
return nil, nil
}))
_, err := rt.RoundTrip(context.Background(), &Request{Arguments: map[string]interface{}{
ArgsBindings: map[string]interface{}{},
_, err := rt.RoundTrip(context.Background(), &Request{Arguments: map[string]any{
ArgsBindings: map[string]any{},
}})
assert.NoError(t, err)
}

View File

@@ -7,58 +7,58 @@ package __
import "entgo.io/ent/dialect/gremlin/graph/dsl"
// As is the api for calling __.As().
func As(args ...interface{}) *dsl.Traversal { return New().As(args...) }
func As(args ...any) *dsl.Traversal { return New().As(args...) }
// Is is the api for calling __.Is().
func Is(args ...interface{}) *dsl.Traversal { return New().Is(args...) }
func Is(args ...any) *dsl.Traversal { return New().Is(args...) }
// Not is the api for calling __.Not().
func Not(args ...interface{}) *dsl.Traversal { return New().Not(args...) }
func Not(args ...any) *dsl.Traversal { return New().Not(args...) }
// Has is the api for calling __.Has().
func Has(args ...interface{}) *dsl.Traversal { return New().Has(args...) }
func Has(args ...any) *dsl.Traversal { return New().Has(args...) }
// HasNot is the api for calling __.HasNot().
func HasNot(args ...interface{}) *dsl.Traversal { return New().HasNot(args...) }
func HasNot(args ...any) *dsl.Traversal { return New().HasNot(args...) }
// Or is the api for calling __.Or().
func Or(args ...interface{}) *dsl.Traversal { return New().Or(args...) }
func Or(args ...any) *dsl.Traversal { return New().Or(args...) }
// And is the api for calling __.And().
func And(args ...interface{}) *dsl.Traversal { return New().And(args...) }
func And(args ...any) *dsl.Traversal { return New().And(args...) }
// In is the api for calling __.In().
func In(args ...interface{}) *dsl.Traversal { return New().In(args...) }
func In(args ...any) *dsl.Traversal { return New().In(args...) }
// Out is the api for calling __.Out().
func Out(args ...interface{}) *dsl.Traversal { return New().Out(args...) }
func Out(args ...any) *dsl.Traversal { return New().Out(args...) }
// OutE is the api for calling __.OutE().
func OutE(args ...interface{}) *dsl.Traversal { return New().OutE(args...) }
func OutE(args ...any) *dsl.Traversal { return New().OutE(args...) }
// InE is the api for calling __.InE().
func InE(args ...interface{}) *dsl.Traversal { return New().InE(args...) }
func InE(args ...any) *dsl.Traversal { return New().InE(args...) }
// InV is the api for calling __.InV().
func InV(args ...interface{}) *dsl.Traversal { return New().InV(args...) }
func InV(args ...any) *dsl.Traversal { return New().InV(args...) }
// V is the api for calling __.V().
func V(args ...interface{}) *dsl.Traversal { return New().V(args...) }
func V(args ...any) *dsl.Traversal { return New().V(args...) }
// OutV is the api for calling __.OutV().
func OutV(args ...interface{}) *dsl.Traversal { return New().OutV(args...) }
func OutV(args ...any) *dsl.Traversal { return New().OutV(args...) }
// Values is the api for calling __.Values().
func Values(args ...string) *dsl.Traversal { return New().Values(args...) }
// Union is the api for calling __.Union().
func Union(args ...interface{}) *dsl.Traversal { return New().Union(args...) }
func Union(args ...any) *dsl.Traversal { return New().Union(args...) }
// Constant is the api for calling __.Constant().
func Constant(args ...interface{}) *dsl.Traversal { return New().Constant(args...) }
func Constant(args ...any) *dsl.Traversal { return New().Constant(args...) }
// Properties is the api for calling __.Properties().
func Properties(args ...interface{}) *dsl.Traversal { return New().Properties(args...) }
func Properties(args ...any) *dsl.Traversal { return New().Properties(args...) }
// OtherV is the api for calling __.OtherV().
func OtherV() *dsl.Traversal { return New().OtherV() }

View File

@@ -18,7 +18,7 @@ import (
// Node represents a DSL step in the traversal.
type Node interface {
// Code returns the code representation of the element and its bindings (if any).
Code() (string, []interface{})
Code() (string, []any)
}
type (
@@ -26,46 +26,46 @@ type (
Token string
// List represents a list of elements.
List struct {
Elements []interface{}
Elements []any
}
// Func represents a function call.
Func struct {
Name string
Args []interface{}
Args []any
}
// Block represents a block/group of nodes.
Block struct {
Nodes []interface{}
Nodes []any
}
// Var represents a variable assignment and usage.
Var struct {
Name string
Elem interface{}
Elem any
}
)
// Code stringified the token.
func (t Token) Code() (string, []interface{}) { return string(t), nil }
func (t Token) Code() (string, []any) { return string(t), nil }
// Code returns the code representation of a list.
func (l List) Code() (string, []interface{}) {
func (l List) Code() (string, []any) {
c, args := codeList(", ", l.Elements...)
return fmt.Sprintf("[%s]", c), args
}
// Code returns the code representation of a function call.
func (f Func) Code() (string, []interface{}) {
func (f Func) Code() (string, []any) {
c, args := codeList(", ", f.Args...)
return fmt.Sprintf("%s(%s)", f.Name, c), args
}
// Code returns the code representation of group/block of nodes.
func (b Block) Code() (string, []interface{}) {
func (b Block) Code() (string, []any) {
return codeList("; ", b.Nodes...)
}
// Code returns the code representation of variable declaration or its identifier.
func (v Var) Code() (string, []interface{}) {
func (v Var) Code() (string, []any) {
c, args := code(v.Elem)
if v.Name == "" {
return c, args
@@ -80,12 +80,12 @@ var (
)
// NewFunc returns a new function node.
func NewFunc(name string, args ...interface{}) *Func {
func NewFunc(name string, args ...any) *Func {
return &Func{Name: name, Args: args}
}
// NewList returns a new list node.
func NewList(args ...interface{}) *List {
func NewList(args ...any) *List {
return &List{Elements: args}
}
@@ -96,10 +96,10 @@ type Querier interface {
}
// Bindings are used to associate a variable with a value.
type Bindings map[string]interface{}
type Bindings map[string]any
// Add adds new value to the bindings map, formats it if needed, and returns its generated name.
func (b Bindings) Add(v interface{}) string {
func (b Bindings) Add(v any) string {
k := fmt.Sprintf("$%x", len(b))
switch v := v.(type) {
case time.Time:
@@ -120,7 +120,7 @@ const (
)
// Code implements the Node interface.
func (c Cardinality) Code() (string, []interface{}) { return string(c), nil }
func (c Cardinality) Code() (string, []any) { return string(c), nil }
// Keyword defines a Gremlin keyword.
type Keyword string
@@ -131,7 +131,7 @@ const (
)
// Code implements the Node interface.
func (k Keyword) Code() (string, []interface{}) { return string(k), nil }
func (k Keyword) Code() (string, []any) { return string(k), nil }
// Order of vertex properties.
type Order string
@@ -144,7 +144,7 @@ const (
)
// Code implements the Node interface.
func (o Order) Code() (string, []interface{}) { return string(o), nil }
func (o Order) Code() (string, []any) { return string(o), nil }
// Column references a particular type of column in a complex data structure such as a Map, a Map.Entry, or a Path.
type Column string
@@ -156,7 +156,7 @@ const (
)
// Code implements the Node interface.
func (o Column) Code() (string, []interface{}) { return string(o), nil }
func (o Column) Code() (string, []any) { return string(o), nil }
// Scope used for steps that have a variable scope which alter the manner in which the step will behave in relation to how the traverses are processed.
type Scope string
@@ -168,12 +168,12 @@ const (
)
// Code implements the Node interface.
func (s Scope) Code() (string, []interface{}) { return string(s), nil }
func (s Scope) Code() (string, []any) { return string(s), nil }
func codeList(sep string, vs ...interface{}) (string, []interface{}) {
func codeList(sep string, vs ...any) (string, []any) {
var (
br strings.Builder
args []interface{}
args []any
)
for i, node := range vs {
if i > 0 {
@@ -186,14 +186,14 @@ func codeList(sep string, vs ...interface{}) (string, []interface{}) {
return br.String(), args
}
func code(v interface{}) (string, []interface{}) {
func code(v any) (string, []any) {
switch n := v.(type) {
case Node:
return n.Code()
case *Traversal:
var (
b strings.Builder
args []interface{}
args []any
)
for i := range n.nodes {
code, nargs := n.nodes[i].Code()
@@ -202,11 +202,11 @@ func code(v interface{}) (string, []interface{}) {
}
return b.String(), args
default:
return "%s", []interface{}{v}
return "%s", []any{v}
}
}
func sface(args []string) (v []interface{}) {
func sface(args []string) (v []any) {
for _, s := range args {
v = append(v, s)
}

View File

@@ -43,14 +43,14 @@ func TestTraverse(t *testing.T) {
wantBinds: dsl.Bindings{"$0": "person", "$1": "name", "$2": "a8m"},
},
{
input: dsl.Each([]interface{}{1, 2, 3}, func(it *dsl.Traversal) *dsl.Traversal {
input: dsl.Each([]any{1, 2, 3}, func(it *dsl.Traversal) *dsl.Traversal {
return g.V(it)
}),
wantQuery: "[$0, $1, $2].each { g.V(it) }",
wantBinds: dsl.Bindings{"$0": 1, "$1": 2, "$2": 3},
},
{
input: dsl.Each([]interface{}{g.V(1).Next()}, func(it *dsl.Traversal) *dsl.Traversal {
input: dsl.Each([]any{g.V(1).Next()}, func(it *dsl.Traversal) *dsl.Traversal {
return it.ID()
}),
wantQuery: "[g.V($0).next()].each { it.id() }",
@@ -74,7 +74,7 @@ func TestTraverse(t *testing.T) {
{
input: func() *dsl.Traversal {
v1 := g.AddV("person")
each := dsl.Each([]interface{}{1, 2, 3}, func(it *dsl.Traversal) *dsl.Traversal {
each := dsl.Each([]any{1, 2, 3}, func(it *dsl.Traversal) *dsl.Traversal {
return g.V(v1).AddE("knows").To(g.V(it)).Next()
})
return dsl.Group(v1, each)

View File

@@ -7,13 +7,13 @@ package g
import "entgo.io/ent/dialect/gremlin/graph/dsl"
// V is the api for calling g.V().
func V(args ...interface{}) *dsl.Traversal { return dsl.NewTraversal().V(args...) }
func V(args ...any) *dsl.Traversal { return dsl.NewTraversal().V(args...) }
// E is the api for calling g.E().
func E(args ...interface{}) *dsl.Traversal { return dsl.NewTraversal().E(args...) }
func E(args ...any) *dsl.Traversal { return dsl.NewTraversal().E(args...) }
// AddV is the api for calling g.AddV().
func AddV(args ...interface{}) *dsl.Traversal { return dsl.NewTraversal().AddV(args...) }
func AddV(args ...any) *dsl.Traversal { return dsl.NewTraversal().AddV(args...) }
// AddE is the api for calling g.AddE().
func AddE(args ...interface{}) *dsl.Traversal { return dsl.NewTraversal().AddE(args...) }
func AddE(args ...any) *dsl.Traversal { return dsl.NewTraversal().AddE(args...) }

View File

@@ -9,37 +9,37 @@ import (
)
// EQ is the equal predicate.
func EQ(v interface{}) *dsl.Traversal {
func EQ(v any) *dsl.Traversal {
return op("eq", v)
}
// NEQ is the not-equal predicate.
func NEQ(v interface{}) *dsl.Traversal {
func NEQ(v any) *dsl.Traversal {
return op("neq", v)
}
// GT is the greater than predicate.
func GT(v interface{}) *dsl.Traversal {
func GT(v any) *dsl.Traversal {
return op("gt", v)
}
// GTE is the greater than or equal predicate.
func GTE(v interface{}) *dsl.Traversal {
func GTE(v any) *dsl.Traversal {
return op("gte", v)
}
// LT is the less than predicate.
func LT(v interface{}) *dsl.Traversal {
func LT(v any) *dsl.Traversal {
return op("lt", v)
}
// LTE is the less than or equal predicate.
func LTE(v interface{}) *dsl.Traversal {
func LTE(v any) *dsl.Traversal {
return op("lte", v)
}
// Between is the between/contains predicate.
func Between(v, u interface{}) *dsl.Traversal {
func Between(v, u any) *dsl.Traversal {
return op("between", v, u)
}
@@ -74,16 +74,16 @@ func NotContaining(substr string) *dsl.Traversal {
}
// Within Determines if a value is within the specified list of values.
func Within(args ...interface{}) *dsl.Traversal {
func Within(args ...any) *dsl.Traversal {
return op("within", args...)
}
// Without determines if a value is not within the specified list of values.
func Without(args ...interface{}) *dsl.Traversal {
func Without(args ...any) *dsl.Traversal {
return op("without", args...)
}
func op(name string, args ...interface{}) *dsl.Traversal {
func op(name string, args ...any) *dsl.Traversal {
t := &dsl.Traversal{}
return t.Add(dsl.NewFunc(name, args...))
}

View File

@@ -55,7 +55,7 @@ func Join(trs ...*Traversal) *Traversal {
}
// V step is usually used to start a traversal but it may also be used mid-traversal.
func (t *Traversal) V(args ...interface{}) *Traversal {
func (t *Traversal) V(args ...any) *Traversal {
t.Add(Dot, NewFunc("V", args...))
return t
}
@@ -67,19 +67,19 @@ func (t *Traversal) OtherV() *Traversal {
}
// E step is usually used to start a traversal but it may also be used mid-traversal.
func (t *Traversal) E(args ...interface{}) *Traversal {
func (t *Traversal) E(args ...any) *Traversal {
t.Add(Dot, NewFunc("E", args...))
return t
}
// AddV adds a vertex.
func (t *Traversal) AddV(args ...interface{}) *Traversal {
func (t *Traversal) AddV(args ...any) *Traversal {
t.Add(Dot, NewFunc("addV", args...))
return t
}
// AddE adds an edge.
func (t *Traversal) AddE(args ...interface{}) *Traversal {
func (t *Traversal) AddE(args ...any) *Traversal {
t.Add(Dot, NewFunc("addE", args...))
return t
}
@@ -96,39 +96,39 @@ func (t *Traversal) Drop() *Traversal {
// Property sets a Property value and related meta properties if supplied,
// if supported by the Graph and if the Element is a VertexProperty.
func (t *Traversal) Property(args ...interface{}) *Traversal {
func (t *Traversal) Property(args ...any) *Traversal {
return t.Add(Dot, NewFunc("property", args...))
}
// Both maps the Vertex to its adjacent vertices given the edge labels.
func (t *Traversal) Both(args ...interface{}) *Traversal {
func (t *Traversal) Both(args ...any) *Traversal {
return t.Add(Dot, NewFunc("both", args...))
}
// BothE maps the Vertex to its incident edges given the edge labels.
func (t *Traversal) BothE(args ...interface{}) *Traversal {
func (t *Traversal) BothE(args ...any) *Traversal {
return t.Add(Dot, NewFunc("bothE", args...))
}
// Has filters vertices, edges and vertex properties based on their properties.
// See: http://tinkerpop.apache.org/docs/current/reference/#has-step.
func (t *Traversal) Has(args ...interface{}) *Traversal {
func (t *Traversal) Has(args ...any) *Traversal {
return t.Add(Dot, NewFunc("has", args...))
}
// HasNot filters vertices, edges and vertex properties based on the non-existence of properties.
// See: http://tinkerpop.apache.org/docs/current/reference/#has-step.
func (t *Traversal) HasNot(args ...interface{}) *Traversal {
func (t *Traversal) HasNot(args ...any) *Traversal {
return t.Add(Dot, NewFunc("hasNot", args...))
}
// HasID filters vertices, edges and vertex properties based on their identifier.
func (t *Traversal) HasID(args ...interface{}) *Traversal {
func (t *Traversal) HasID(args ...any) *Traversal {
return t.Add(Dot, NewFunc("hasId", args...))
}
// HasLabel filters vertices, edges and vertex properties based on their label.
func (t *Traversal) HasLabel(args ...interface{}) *Traversal {
func (t *Traversal) HasLabel(args ...any) *Traversal {
return t.Add(Dot, NewFunc("hasLabel", args...))
}
@@ -138,17 +138,17 @@ func (t *Traversal) HasNext() *Traversal {
}
// Match maps the Traverser to a Map of bindings as specified by the provided match traversals.
func (t *Traversal) Match(args ...interface{}) *Traversal {
func (t *Traversal) Match(args ...any) *Traversal {
return t.Add(Dot, NewFunc("match", args...))
}
// Choose routes the current traverser to a particular traversal branch option which allows the creation of if-then-else like semantics within a traversal.
func (t *Traversal) Choose(args ...interface{}) *Traversal {
func (t *Traversal) Choose(args ...any) *Traversal {
return t.Add(Dot, NewFunc("choose", args...))
}
// Select arbitrary values from the traversal.
func (t *Traversal) Select(args ...interface{}) *Traversal {
func (t *Traversal) Select(args ...any) *Traversal {
return t.Add(Dot, NewFunc("select", args...))
}
@@ -163,22 +163,22 @@ func (t *Traversal) Values(args ...string) *Traversal {
}
// ValueMap maps the Element to a Map of the property values key'd according to their Property.key().
func (t *Traversal) ValueMap(args ...interface{}) *Traversal {
func (t *Traversal) ValueMap(args ...any) *Traversal {
return t.Add(Dot, NewFunc("valueMap", args...))
}
// Properties maps the Element to its associated properties given the provide property keys.
func (t *Traversal) Properties(args ...interface{}) *Traversal {
func (t *Traversal) Properties(args ...any) *Traversal {
return t.Add(Dot, NewFunc("properties", args...))
}
// Range filters the objects in the traversal by the number of them to pass through the stream.
func (t *Traversal) Range(args ...interface{}) *Traversal {
func (t *Traversal) Range(args ...any) *Traversal {
return t.Add(Dot, NewFunc("range", args...))
}
// Limit filters the objects in the traversal by the number of them to pass through the stream, where only the first n objects are allowed as defined by the limit argument.
func (t *Traversal) Limit(args ...interface{}) *Traversal {
func (t *Traversal) Limit(args ...any) *Traversal {
return t.Add(Dot, NewFunc("limit", args...))
}
@@ -193,72 +193,72 @@ func (t *Traversal) Label() *Traversal {
}
// From provides from()-modulation to respective steps.
func (t *Traversal) From(args ...interface{}) *Traversal {
func (t *Traversal) From(args ...any) *Traversal {
return t.Add(Dot, NewFunc("from", args...))
}
// To used as a modifier to addE(String) this method specifies the traversal to use for selecting the incoming vertex of the newly added Edge.
func (t *Traversal) To(args ...interface{}) *Traversal {
func (t *Traversal) To(args ...any) *Traversal {
return t.Add(Dot, NewFunc("to", args...))
}
// As provides a label to the step that can be accessed later in the traversal by other steps.
func (t *Traversal) As(args ...interface{}) *Traversal {
func (t *Traversal) As(args ...any) *Traversal {
return t.Add(Dot, NewFunc("as", args...))
}
// Or ensures that at least one of the provided traversals yield a result.
func (t *Traversal) Or(args ...interface{}) *Traversal {
func (t *Traversal) Or(args ...any) *Traversal {
return t.Add(Dot, NewFunc("or", args...))
}
// And ensures that all of the provided traversals yield a result.
func (t *Traversal) And(args ...interface{}) *Traversal {
func (t *Traversal) And(args ...any) *Traversal {
return t.Add(Dot, NewFunc("and", args...))
}
// Is filters the E object if it is not P.eq(V) to the provided value.
func (t *Traversal) Is(args ...interface{}) *Traversal {
func (t *Traversal) Is(args ...any) *Traversal {
return t.Add(Dot, NewFunc("is", args...))
}
// Not removes objects from the traversal stream when the traversal provided as an argument does not return any objects.
func (t *Traversal) Not(args ...interface{}) *Traversal {
func (t *Traversal) Not(args ...any) *Traversal {
return t.Add(Dot, NewFunc("not", args...))
}
// In maps the Vertex to its incoming adjacent vertices given the edge labels.
func (t *Traversal) In(args ...interface{}) *Traversal {
func (t *Traversal) In(args ...any) *Traversal {
return t.Add(Dot, NewFunc("in", args...))
}
// Where filters the current object based on the object itself or the path history.
func (t *Traversal) Where(args ...interface{}) *Traversal {
func (t *Traversal) Where(args ...any) *Traversal {
return t.Add(Dot, NewFunc("where", args...))
}
// Out maps the Vertex to its outgoing adjacent vertices given the edge labels.
func (t *Traversal) Out(args ...interface{}) *Traversal {
func (t *Traversal) Out(args ...any) *Traversal {
return t.Add(Dot, NewFunc("out", args...))
}
// OutE maps the Vertex to its outgoing incident edges given the edge labels.
func (t *Traversal) OutE(args ...interface{}) *Traversal {
func (t *Traversal) OutE(args ...any) *Traversal {
return t.Add(Dot, NewFunc("outE", args...))
}
// InE maps the Vertex to its incoming incident edges given the edge labels.
func (t *Traversal) InE(args ...interface{}) *Traversal {
func (t *Traversal) InE(args ...any) *Traversal {
return t.Add(Dot, NewFunc("inE", args...))
}
// OutV maps the Edge to its outgoing/tail incident Vertex.
func (t *Traversal) OutV(args ...interface{}) *Traversal {
func (t *Traversal) OutV(args ...any) *Traversal {
return t.Add(Dot, NewFunc("outV", args...))
}
// InV maps the Edge to its incoming/head incident Vertex.
func (t *Traversal) InV(args ...interface{}) *Traversal {
func (t *Traversal) InV(args ...any) *Traversal {
return t.Add(Dot, NewFunc("inV", args...))
}
@@ -274,18 +274,18 @@ func (t *Traversal) Iterate() *Traversal {
// Count maps the traversal stream to its reduction as a sum of the Traverser.bulk() values
// (i.e. count the number of traversers up to this point).
func (t *Traversal) Count(args ...interface{}) *Traversal {
func (t *Traversal) Count(args ...any) *Traversal {
return t.Add(Dot, NewFunc("count", args...))
}
// Order all the objects in the traversal up to this point and then emit them one-by-one in their ordered sequence.
func (t *Traversal) Order(args ...interface{}) *Traversal {
func (t *Traversal) Order(args ...any) *Traversal {
return t.Add(Dot, NewFunc("order", args...))
}
// By can be applied to a number of different step to alter their behaviors.
// This form is essentially an identity() modulation.
func (t *Traversal) By(args ...interface{}) *Traversal {
func (t *Traversal) By(args ...any) *Traversal {
return t.Add(Dot, NewFunc("by", args...))
}
@@ -300,58 +300,58 @@ func (t *Traversal) Unfold() *Traversal {
}
// Sum maps the traversal stream to its reduction as a sum of the Traverser.get() values multiplied by their Traverser.bulk().
func (t *Traversal) Sum(args ...interface{}) *Traversal {
func (t *Traversal) Sum(args ...any) *Traversal {
return t.Add(Dot, NewFunc("sum", args...))
}
// Mean determines the mean value in the stream.
func (t *Traversal) Mean(args ...interface{}) *Traversal {
func (t *Traversal) Mean(args ...any) *Traversal {
return t.Add(Dot, NewFunc("mean", args...))
}
// Min determines the smallest value in the stream.
func (t *Traversal) Min(args ...interface{}) *Traversal {
func (t *Traversal) Min(args ...any) *Traversal {
return t.Add(Dot, NewFunc("min", args...))
}
// Max determines the greatest value in the stream.
func (t *Traversal) Max(args ...interface{}) *Traversal {
func (t *Traversal) Max(args ...any) *Traversal {
return t.Add(Dot, NewFunc("max", args...))
}
// Coalesce evaluates the provided traversals and returns the result of the first traversal to emit at least one object.
func (t *Traversal) Coalesce(args ...interface{}) *Traversal {
func (t *Traversal) Coalesce(args ...any) *Traversal {
return t.Add(Dot, NewFunc("coalesce", args...))
}
// Dedup removes all duplicates in the traversal stream up to this point.
func (t *Traversal) Dedup(args ...interface{}) *Traversal {
func (t *Traversal) Dedup(args ...any) *Traversal {
return t.Add(Dot, NewFunc("dedup", args...))
}
// Constant maps any object to a fixed E value.
func (t *Traversal) Constant(args ...interface{}) *Traversal {
func (t *Traversal) Constant(args ...any) *Traversal {
return t.Add(Dot, NewFunc("constant", args...))
}
// Union merges the results of an arbitrary number of traversals.
func (t *Traversal) Union(args ...interface{}) *Traversal {
func (t *Traversal) Union(args ...any) *Traversal {
return t.Add(Dot, NewFunc("union", args...))
}
// SideEffect allows the traverser to proceed unchanged, but yield some computational
// sideEffect in the process.
func (t *Traversal) SideEffect(args ...interface{}) *Traversal {
func (t *Traversal) SideEffect(args ...any) *Traversal {
return t.Add(Dot, NewFunc("sideEffect", args...))
}
// Each is a Groovy each-loop function.
func Each(v interface{}, cb func(it *Traversal) *Traversal) *Traversal {
func Each(v any, cb func(it *Traversal) *Traversal) *Traversal {
t := &Traversal{}
switch v := v.(type) {
case *Traversal:
t.Add(&Var{Elem: v})
case []interface{}:
case []any:
t.Add(NewList(v...))
default:
t.Add(Token("undefined"))
@@ -371,7 +371,7 @@ func (t *Traversal) Add(n ...Node) *Traversal {
// Query returns the query-representation and its binding of this traversal object.
func (t *Traversal) Query() (string, Bindings) {
var (
names []interface{}
names []any
query strings.Builder
bindings = Bindings{}
)

View File

@@ -20,15 +20,15 @@ type (
// graphson edge repr.
edge struct {
Element
OutV interface{} `json:"outV"`
OutVLabel string `json:"outVLabel"`
InV interface{} `json:"inV"`
InVLabel string `json:"inVLabel"`
OutV any `json:"outV"`
OutVLabel string `json:"outVLabel"`
InV any `json:"inV"`
InVLabel string `json:"inVLabel"`
}
)
// NewEdge create a new graph edge.
func NewEdge(id interface{}, label string, outV, inV Vertex) Edge {
func NewEdge(id any, label string, outV, inV Vertex) Edge {
return Edge{
Element: NewElement(id, label),
OutV: outV,
@@ -74,12 +74,12 @@ func (edge) GraphsonType() graphson.Type {
// Property denotes a key/value pair associated with an edge.
type Property struct {
Key string `json:"key"`
Value interface{} `json:"value"`
Key string `json:"key"`
Value any `json:"value"`
}
// NewProperty create a new graph edge property.
func NewProperty(key string, value interface{}) Property {
func NewProperty(key string, value any) Property {
return Property{key, value}
}

View File

@@ -6,11 +6,11 @@ package graph
// Element defines a base struct for graph elements.
type Element struct {
ID interface{} `json:"id"`
Label string `json:"label"`
ID any `json:"id"`
Label string `json:"label"`
}
// NewElement create a new graph element.
func NewElement(id interface{}, label string) Element {
func NewElement(id any, label string) Element {
return Element{id, label}
}

View File

@@ -13,10 +13,10 @@ import (
)
// ValueMap models a .valueMap() gremlin response.
type ValueMap []map[string]interface{}
type ValueMap []map[string]any
// Decode decodes a value map into v.
func (m ValueMap) Decode(v interface{}) error {
func (m ValueMap) Decode(v any) error {
rv := reflect.ValueOf(v)
if rv.Kind() != reflect.Ptr {
return errors.New("cannot unmarshal into a non pointer")
@@ -26,14 +26,14 @@ func (m ValueMap) Decode(v interface{}) error {
}
if rv.Elem().Kind() != reflect.Slice {
v = &[]interface{}{v}
v = &[]any{v}
}
return m.decode(v)
}
func (m ValueMap) decode(v interface{}) error {
func (m ValueMap) decode(v any) error {
cfg := mapstructure.DecoderConfig{
DecodeHook: func(f, t reflect.Kind, data interface{}) (interface{}, error) {
DecodeHook: func(f, t reflect.Kind, data any) (any, error) {
if f == reflect.Slice && t != reflect.Slice {
rv := reflect.ValueOf(data)
if rv.Len() == 1 {

View File

@@ -12,11 +12,11 @@ import (
)
func TestValueMapDecodeOne(t *testing.T) {
vm := ValueMap{map[string]interface{}{
vm := ValueMap{map[string]any{
"id": int64(1),
"label": "person",
"name": []interface{}{"marko"},
"age": []interface{}{int32(29)},
"name": []any{"marko"},
"age": []any{int32(29)},
}}
var ent struct {
@@ -36,15 +36,15 @@ func TestValueMapDecodeOne(t *testing.T) {
func TestValueMapDecodeMany(t *testing.T) {
vm := ValueMap{
map[string]interface{}{
map[string]any{
"id": int64(1),
"label": "person",
"name": []interface{}{"chico"},
"name": []any{"chico"},
},
map[string]interface{}{
map[string]any{
"id": int64(2),
"label": "person",
"name": []interface{}{"dico"},
"name": []any{"dico"},
},
}

View File

@@ -16,7 +16,7 @@ type Vertex struct {
}
// NewVertex create a new graph vertex.
func NewVertex(id interface{}, label string) Vertex {
func NewVertex(id any, label string) Vertex {
if label == "" {
label = "vertex"
}
@@ -37,13 +37,13 @@ func (v Vertex) String() string {
// VertexProperty denotes a key/value pair associated with a vertex.
type VertexProperty struct {
ID interface{} `json:"id"`
Key string `json:"label"`
Value interface{} `json:"value"`
ID any `json:"id"`
Key string `json:"label"`
Value any `json:"value"`
}
// NewVertexProperty create a new graph vertex property.
func NewVertexProperty(id interface{}, key string, value interface{}) VertexProperty {
func NewVertexProperty(id any, key string, value any) VertexProperty {
return VertexProperty{
ID: id,
Key: key,

View File

@@ -231,7 +231,7 @@ func (c *Conn) receiver() error {
})
// complete all in flight requests on termination
defer c.inflight.Range(func(id, ifr interface{}) bool {
defer c.inflight.Range(func(id, ifr any) bool {
ifr.(*inflight).result <- result{err: ErrConnClosed}
c.inflight.Delete(id)
return true

View File

@@ -58,14 +58,14 @@ func requestAttrs(req *gremlin.Request, withQuery bool) []trace.Attribute {
if withQuery {
query, _ := req.Arguments[gremlin.ArgsGremlin].(string)
attrs = append(attrs, trace.StringAttribute(QueryAttribute, query))
if bindings, ok := req.Arguments[gremlin.ArgsBindings].(map[string]interface{}); ok {
if bindings, ok := req.Arguments[gremlin.ArgsBindings].(map[string]any); ok {
attrs = append(attrs, bindingsAttrs(bindings)...)
}
}
return attrs
}
func bindingsAttrs(bindings map[string]interface{}) []trace.Attribute {
func bindingsAttrs(bindings map[string]any) []trace.Attribute {
attrs := make([]trace.Attribute, 0, len(bindings))
for key, val := range bindings {
key = BindingAttribute + "." + key
@@ -74,7 +74,7 @@ func bindingsAttrs(bindings map[string]interface{}) []trace.Attribute {
return attrs
}
func bindingToAttr(key string, val interface{}) trace.Attribute {
func bindingToAttr(key string, val any) trace.Attribute {
switch v := val.(type) {
case nil:
return trace.StringAttribute(key, "")

View File

@@ -134,7 +134,7 @@ func TestRequestAttributes(t *testing.T) {
{
name: "Query with bindings",
makeReq: func() *gremlin.Request {
bindings := map[string]interface{}{
bindings := map[string]any{
"$1": "user", "$2": int64(42),
"$3": 3.14, "$4": bytes.Repeat([]byte{0xff}, 257),
"$5": true, "$6": nil,

View File

@@ -16,10 +16,10 @@ import (
type (
// A Request models a request message sent to the server.
Request struct {
RequestID string `json:"requestId" graphson:"g:UUID"`
Operation string `json:"op"`
Processor string `json:"processor"`
Arguments map[string]interface{} `json:"args"`
RequestID string `json:"requestId" graphson:"g:UUID"`
Operation string `json:"op"`
Processor string `json:"processor"`
Arguments map[string]any `json:"args"`
}
// RequestOption enables request customization.
@@ -34,7 +34,7 @@ func NewEvalRequest(query string, opts ...RequestOption) *Request {
r := &Request{
RequestID: uuid.New().String(),
Operation: OpsEval,
Arguments: map[string]interface{}{
Arguments: map[string]any{
ArgsGremlin: query,
ArgsLanguage: "gremlin-groovy",
},
@@ -50,7 +50,7 @@ func NewAuthRequest(requestID, username, password string) *Request {
return &Request{
RequestID: requestID,
Operation: OpsAuthentication,
Arguments: map[string]interface{}{
Arguments: map[string]any{
ArgsSasl: Credentials{
Username: username,
Password: password,
@@ -61,7 +61,7 @@ func NewAuthRequest(requestID, username, password string) *Request {
}
// WithBindings sets request bindings.
func WithBindings(bindings map[string]interface{}) RequestOption {
func WithBindings(bindings map[string]any) RequestOption {
return func(r *Request) {
r.Arguments[ArgsBindings] = bindings
}

View File

@@ -17,36 +17,36 @@ import (
func TestEvaluateRequestEncode(t *testing.T) {
req := NewEvalRequest("g.V(x)",
WithBindings(map[string]interface{}{"x": 1}),
WithBindings(map[string]any{"x": 1}),
WithEvalTimeout(time.Second),
)
data, err := graphson.Marshal(req)
require.NoError(t, err)
var got map[string]interface{}
var got map[string]any
err = json.Unmarshal(data, &got)
require.NoError(t, err)
assert.Equal(t, map[string]interface{}{
assert.Equal(t, map[string]any{
"@type": "g:UUID",
"@value": req.RequestID,
}, got["requestId"])
assert.Equal(t, req.Operation, got["op"])
assert.Equal(t, req.Processor, got["processor"])
args := got["args"].(map[string]interface{})
args := got["args"].(map[string]any)
assert.Equal(t, "g:Map", args["@type"])
assert.ElementsMatch(t, args["@value"], []interface{}{
assert.ElementsMatch(t, args["@value"], []any{
"gremlin", "g.V(x)", "language", "gremlin-groovy",
"scriptEvaluationTimeout", map[string]interface{}{
"scriptEvaluationTimeout", map[string]any{
"@type": "g:Int64",
"@value": float64(1000),
},
"bindings", map[string]interface{}{
"bindings", map[string]any{
"@type": "g:Map",
"@value": []interface{}{
"@value": []any{
"x",
map[string]interface{}{
map[string]any{
"@type": "g:Int64",
"@value": float64(1),
},
@@ -67,20 +67,20 @@ func TestAuthenticateRequestEncode(t *testing.T) {
data, err := graphson.Marshal(req)
require.NoError(t, err)
var got map[string]interface{}
var got map[string]any
err = json.Unmarshal(data, &got)
require.NoError(t, err)
assert.Equal(t, map[string]interface{}{
assert.Equal(t, map[string]any{
"@type": "g:UUID",
"@value": req.RequestID,
}, got["requestId"])
assert.Equal(t, req.Operation, got["op"])
assert.Equal(t, req.Processor, got["processor"])
args := got["args"].(map[string]interface{})
args := got["args"].(map[string]any)
assert.Equal(t, "g:Map", args["@type"])
assert.ElementsMatch(t, args["@value"], []interface{}{
assert.ElementsMatch(t, args["@value"], []any{
"sasl", "AHVzZXIAcGFzcw==", "saslMechanism", "PLAIN",
})
}

View File

@@ -16,13 +16,13 @@ import (
type Response struct {
RequestID string `json:"requestId" graphson:"g:UUID"`
Status struct {
Code int `json:"code"`
Attributes map[string]interface{} `json:"attributes"`
Message string `json:"message"`
Code int `json:"code"`
Attributes map[string]any `json:"attributes"`
Message string `json:"message"`
} `json:"status"`
Result struct {
Data graphson.RawMessage `json:"data"`
Meta map[string]interface{} `json:"meta"`
Data graphson.RawMessage `json:"data"`
Meta map[string]any `json:"meta"`
} `json:"result"`
}
@@ -45,7 +45,7 @@ func (rsp *Response) Err() error {
}
// ReadVal reads gremlin response data into v.
func (rsp *Response) ReadVal(v interface{}) error {
func (rsp *Response) ReadVal(v any) error {
if err := rsp.Err(); err != nil {
return err
}

View File

@@ -194,7 +194,7 @@ func TestResponseReadGraphElements(t *testing.T) {
tests := []struct {
method string
data string
want interface{}
want any
}{
{
method: "ReadVertices",