forked from cerc-io/laconicd-deprecated
Fix golang-ci lint errors
This commit is contained in:
parent
e004584685
commit
c3e0102571
@ -121,7 +121,7 @@ func (q queryResolver) QueryRecords(ctx context.Context, attributes []*KeyValueI
|
||||
res, err := nsQueryClient.ListRecords(
|
||||
context.Background(),
|
||||
®istrytypes.QueryListRecordsRequest{
|
||||
Attributes: toRpcAttributes(attributes),
|
||||
Attributes: toRPCAttributes(attributes),
|
||||
All: (all != nil && *all),
|
||||
},
|
||||
)
|
||||
|
24
gql/util.go
24
gql/util.go
@ -256,43 +256,43 @@ func GetGQLAuction(auction *auctiontypes.Auction, bids []*auctiontypes.Bid) (*Au
|
||||
return &gqlAuction, nil
|
||||
}
|
||||
|
||||
func toRpcValue(value *ValueInput) *registrytypes.QueryListRecordsRequest_ValueInput {
|
||||
func toRPCValue(value *ValueInput) *registrytypes.QueryListRecordsRequest_ValueInput {
|
||||
var rpcval registrytypes.QueryListRecordsRequest_ValueInput
|
||||
|
||||
switch {
|
||||
case value == nil:
|
||||
return nil
|
||||
case value.Int != nil:
|
||||
rpcval.Value = ®istrytypes.QueryListRecordsRequest_ValueInput_Int{int64(*value.Int)}
|
||||
rpcval.Value = ®istrytypes.QueryListRecordsRequest_ValueInput_Int{Int: int64(*value.Int)}
|
||||
case value.Float != nil:
|
||||
rpcval.Value = ®istrytypes.QueryListRecordsRequest_ValueInput_Float{*value.Float}
|
||||
rpcval.Value = ®istrytypes.QueryListRecordsRequest_ValueInput_Float{Float: *value.Float}
|
||||
case value.String != nil:
|
||||
rpcval.Value = ®istrytypes.QueryListRecordsRequest_ValueInput_String_{*value.String}
|
||||
rpcval.Value = ®istrytypes.QueryListRecordsRequest_ValueInput_String_{String_: *value.String}
|
||||
case value.Boolean != nil:
|
||||
rpcval.Value = ®istrytypes.QueryListRecordsRequest_ValueInput_Boolean{*value.Boolean}
|
||||
rpcval.Value = ®istrytypes.QueryListRecordsRequest_ValueInput_Boolean{Boolean: *value.Boolean}
|
||||
case value.Link != nil:
|
||||
rpcval.Value = ®istrytypes.QueryListRecordsRequest_ValueInput_Link{value.Link.String()}
|
||||
rpcval.Value = ®istrytypes.QueryListRecordsRequest_ValueInput_Link{Link: value.Link.String()}
|
||||
case value.Array != nil:
|
||||
var contents registrytypes.QueryListRecordsRequest_ArrayInput
|
||||
for _, val := range value.Array {
|
||||
contents.Values = append(contents.Values, toRpcValue(val))
|
||||
contents.Values = append(contents.Values, toRPCValue(val))
|
||||
}
|
||||
rpcval.Value = ®istrytypes.QueryListRecordsRequest_ValueInput_Array{&contents}
|
||||
rpcval.Value = ®istrytypes.QueryListRecordsRequest_ValueInput_Array{Array: &contents}
|
||||
case value.Map != nil:
|
||||
var contents registrytypes.QueryListRecordsRequest_MapInput
|
||||
for _, kv := range value.Map {
|
||||
contents.Values[kv.Key] = toRpcValue(kv.Value)
|
||||
contents.Values[kv.Key] = toRPCValue(kv.Value)
|
||||
}
|
||||
rpcval.Value = ®istrytypes.QueryListRecordsRequest_ValueInput_Map{&contents}
|
||||
rpcval.Value = ®istrytypes.QueryListRecordsRequest_ValueInput_Map{Map: &contents}
|
||||
}
|
||||
return &rpcval
|
||||
}
|
||||
|
||||
func toRpcAttributes(attrs []*KeyValueInput) []*registrytypes.QueryListRecordsRequest_KeyValueInput {
|
||||
func toRPCAttributes(attrs []*KeyValueInput) []*registrytypes.QueryListRecordsRequest_KeyValueInput {
|
||||
kvPairs := []*registrytypes.QueryListRecordsRequest_KeyValueInput{}
|
||||
|
||||
for _, value := range attrs {
|
||||
parsedValue := toRpcValue(value.Value)
|
||||
parsedValue := toRPCValue(value.Value)
|
||||
kvPair := ®istrytypes.QueryListRecordsRequest_KeyValueInput{
|
||||
Key: value.Key,
|
||||
Value: parsedValue,
|
||||
|
@ -197,22 +197,40 @@ func QueryValueToJSON(input *types.QueryListRecordsRequest_ValueInput) ([]byte,
|
||||
|
||||
switch value := input.GetValue().(type) {
|
||||
case *types.QueryListRecordsRequest_ValueInput_String_:
|
||||
nb.AssignString(value.String_)
|
||||
err := nb.AssignString(value.String_)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case *types.QueryListRecordsRequest_ValueInput_Int:
|
||||
nb.AssignInt(value.Int)
|
||||
|
||||
err := nb.AssignInt(value.Int)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case *types.QueryListRecordsRequest_ValueInput_Float:
|
||||
nb.AssignFloat(value.Float)
|
||||
|
||||
err := nb.AssignFloat(value.Float)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case *types.QueryListRecordsRequest_ValueInput_Boolean:
|
||||
nb.AssignBool(value.Boolean)
|
||||
|
||||
err := nb.AssignBool(value.Boolean)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case *types.QueryListRecordsRequest_ValueInput_Link:
|
||||
link := cidlink.Link{Cid: cid.MustParse(value.Link)}
|
||||
nb.AssignLink(link)
|
||||
err := nb.AssignLink(link)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case *types.QueryListRecordsRequest_ValueInput_Array:
|
||||
return nil, fmt.Errorf("Recursive query values are not supported")
|
||||
return nil, fmt.Errorf("recursive query values are not supported")
|
||||
case *types.QueryListRecordsRequest_ValueInput_Map:
|
||||
return nil, fmt.Errorf("Recursive query values are not supported")
|
||||
return nil, fmt.Errorf("recursive query values are not supported")
|
||||
default:
|
||||
return nil, fmt.Errorf("Value has unexpected type %T", value)
|
||||
return nil, fmt.Errorf("value has unexpected type %T", value)
|
||||
}
|
||||
|
||||
n := nb.Build()
|
||||
@ -377,7 +395,7 @@ func (k Keeper) processAttributes(ctx sdk.Context, attrs types.AttributeMap, id
|
||||
}
|
||||
n := nb.Build()
|
||||
if n.Kind() != ipld.Kind_Map {
|
||||
return fmt.Errorf("Record attributes must be a map, not %T", n.Kind())
|
||||
return fmt.Errorf("record attributes must be a map, not %T", n.Kind())
|
||||
}
|
||||
|
||||
return k.processAttributeMap(ctx, n, id, prefix)
|
||||
@ -385,6 +403,7 @@ func (k Keeper) processAttributes(ctx sdk.Context, attrs types.AttributeMap, id
|
||||
|
||||
func (k Keeper) processAttributeMap(ctx sdk.Context, n ipld.Node, id string, prefix string) error {
|
||||
for it := n.MapIterator(); !it.Done(); {
|
||||
//nolint:misspell
|
||||
keynode, valuenode, err := it.Next()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -99,7 +99,7 @@ func (r *Record) ToReadableRecord() ReadableRecord {
|
||||
func (r *ReadableRecord) CanonicalJSON() []byte {
|
||||
bytes, err := canonicaljson.Marshal(r.Attributes)
|
||||
if err != nil {
|
||||
panic("error marshalling record: " + err.Error())
|
||||
panic("error marshaling record: " + err.Error())
|
||||
}
|
||||
|
||||
return bytes
|
||||
|
Loading…
Reference in New Issue
Block a user