Fix golang-ci lint errors

This commit is contained in:
neeraj 2024-01-11 11:24:26 +05:30
parent e004584685
commit c3e0102571
4 changed files with 42 additions and 23 deletions

View File

@ -121,7 +121,7 @@ func (q queryResolver) QueryRecords(ctx context.Context, attributes []*KeyValueI
res, err := nsQueryClient.ListRecords( res, err := nsQueryClient.ListRecords(
context.Background(), context.Background(),
&registrytypes.QueryListRecordsRequest{ &registrytypes.QueryListRecordsRequest{
Attributes: toRpcAttributes(attributes), Attributes: toRPCAttributes(attributes),
All: (all != nil && *all), All: (all != nil && *all),
}, },
) )

View File

@ -256,43 +256,43 @@ func GetGQLAuction(auction *auctiontypes.Auction, bids []*auctiontypes.Bid) (*Au
return &gqlAuction, nil return &gqlAuction, nil
} }
func toRpcValue(value *ValueInput) *registrytypes.QueryListRecordsRequest_ValueInput { func toRPCValue(value *ValueInput) *registrytypes.QueryListRecordsRequest_ValueInput {
var rpcval registrytypes.QueryListRecordsRequest_ValueInput var rpcval registrytypes.QueryListRecordsRequest_ValueInput
switch { switch {
case value == nil: case value == nil:
return nil return nil
case value.Int != nil: case value.Int != nil:
rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Int{int64(*value.Int)} rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Int{Int: int64(*value.Int)}
case value.Float != nil: case value.Float != nil:
rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Float{*value.Float} rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Float{Float: *value.Float}
case value.String != nil: case value.String != nil:
rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_String_{*value.String} rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_String_{String_: *value.String}
case value.Boolean != nil: case value.Boolean != nil:
rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Boolean{*value.Boolean} rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Boolean{Boolean: *value.Boolean}
case value.Link != nil: case value.Link != nil:
rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Link{value.Link.String()} rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Link{Link: value.Link.String()}
case value.Array != nil: case value.Array != nil:
var contents registrytypes.QueryListRecordsRequest_ArrayInput var contents registrytypes.QueryListRecordsRequest_ArrayInput
for _, val := range value.Array { for _, val := range value.Array {
contents.Values = append(contents.Values, toRpcValue(val)) contents.Values = append(contents.Values, toRPCValue(val))
} }
rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Array{&contents} rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Array{Array: &contents}
case value.Map != nil: case value.Map != nil:
var contents registrytypes.QueryListRecordsRequest_MapInput var contents registrytypes.QueryListRecordsRequest_MapInput
for _, kv := range value.Map { for _, kv := range value.Map {
contents.Values[kv.Key] = toRpcValue(kv.Value) contents.Values[kv.Key] = toRPCValue(kv.Value)
} }
rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Map{&contents} rpcval.Value = &registrytypes.QueryListRecordsRequest_ValueInput_Map{Map: &contents}
} }
return &rpcval return &rpcval
} }
func toRpcAttributes(attrs []*KeyValueInput) []*registrytypes.QueryListRecordsRequest_KeyValueInput { func toRPCAttributes(attrs []*KeyValueInput) []*registrytypes.QueryListRecordsRequest_KeyValueInput {
kvPairs := []*registrytypes.QueryListRecordsRequest_KeyValueInput{} kvPairs := []*registrytypes.QueryListRecordsRequest_KeyValueInput{}
for _, value := range attrs { for _, value := range attrs {
parsedValue := toRpcValue(value.Value) parsedValue := toRPCValue(value.Value)
kvPair := &registrytypes.QueryListRecordsRequest_KeyValueInput{ kvPair := &registrytypes.QueryListRecordsRequest_KeyValueInput{
Key: value.Key, Key: value.Key,
Value: parsedValue, Value: parsedValue,

View File

@ -197,22 +197,40 @@ func QueryValueToJSON(input *types.QueryListRecordsRequest_ValueInput) ([]byte,
switch value := input.GetValue().(type) { switch value := input.GetValue().(type) {
case *types.QueryListRecordsRequest_ValueInput_String_: 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: 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: 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: 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: case *types.QueryListRecordsRequest_ValueInput_Link:
link := cidlink.Link{Cid: cid.MustParse(value.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: 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: 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: default:
return nil, fmt.Errorf("Value has unexpected type %T", value) return nil, fmt.Errorf("value has unexpected type %T", value)
} }
n := nb.Build() n := nb.Build()
@ -377,7 +395,7 @@ func (k Keeper) processAttributes(ctx sdk.Context, attrs types.AttributeMap, id
} }
n := nb.Build() n := nb.Build()
if n.Kind() != ipld.Kind_Map { 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) 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 { func (k Keeper) processAttributeMap(ctx sdk.Context, n ipld.Node, id string, prefix string) error {
for it := n.MapIterator(); !it.Done(); { for it := n.MapIterator(); !it.Done(); {
//nolint:misspell
keynode, valuenode, err := it.Next() keynode, valuenode, err := it.Next()
if err != nil { if err != nil {
return err return err

View File

@ -99,7 +99,7 @@ func (r *Record) ToReadableRecord() ReadableRecord {
func (r *ReadableRecord) CanonicalJSON() []byte { func (r *ReadableRecord) CanonicalJSON() []byte {
bytes, err := canonicaljson.Marshal(r.Attributes) bytes, err := canonicaljson.Marshal(r.Attributes)
if err != nil { if err != nil {
panic("error marshalling record: " + err.Error()) panic("error marshaling record: " + err.Error())
} }
return bytes return bytes