Skip to content

Commit

Permalink
Fix return type
Browse files Browse the repository at this point in the history
Signed-off-by: Yury-Fridlyand <yury.fridlyand@improving.com>
  • Loading branch information
Yury-Fridlyand committed Jan 16, 2025
1 parent d3eaf55 commit 0d06f67
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 34 deletions.
16 changes: 8 additions & 8 deletions go/api/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1803,7 +1803,7 @@ func (client *baseClient) XAutoClaim(
consumer string,
minIdleTime int64,
start string,
) (*XAutoClaimResponse, error) {
) (XAutoClaimResponse, error) {
return client.XAutoClaimWithOptions(key, group, consumer, minIdleTime, start, nil)
}

Expand Down Expand Up @@ -1862,18 +1862,18 @@ func (client *baseClient) XAutoClaimWithOptions(
minIdleTime int64,
start string,
options *options.XAutoClaimOptions,
) (*XAutoClaimResponse, error) {
) (XAutoClaimResponse, error) {
args := []string{key, group, consumer, utils.IntToString(minIdleTime), start}
if options != nil {
optArgs, err := options.ToArgs()
if err != nil {
return nil, err
return XAutoClaimResponse{}, err
}
args = append(args, optArgs...)
}
result, err := client.executeCommand(C.XAutoClaim, args)
if err != nil {
return nil, err
return XAutoClaimResponse{}, err
}
return handleXAutoClaimResponse(result)
}
Expand Down Expand Up @@ -1928,7 +1928,7 @@ func (client *baseClient) XAutoClaimJustId(
consumer string,
minIdleTime int64,
start string,
) (*XAutoClaimJustIdResponse, error) {
) (XAutoClaimJustIdResponse, error) {
return client.XAutoClaimJustIdWithOptions(key, group, consumer, minIdleTime, start, nil)
}

Expand Down Expand Up @@ -1985,19 +1985,19 @@ func (client *baseClient) XAutoClaimJustIdWithOptions(
minIdleTime int64,
start string,
options *options.XAutoClaimOptions,
) (*XAutoClaimJustIdResponse, error) {
) (XAutoClaimJustIdResponse, error) {
args := []string{key, group, consumer, utils.IntToString(minIdleTime), start}
if options != nil {
optArgs, err := options.ToArgs()
if err != nil {
return nil, err
return XAutoClaimJustIdResponse{}, err
}
args = append(args, optArgs...)
}
args = append(args, "JUSTID")
result, err := client.executeCommand(C.XAutoClaim, args)
if err != nil {
return nil, err
return XAutoClaimJustIdResponse{}, err
}
return handleXAutoClaimJustIdResponse(result)
}
Expand Down
38 changes: 20 additions & 18 deletions go/api/response_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,20 +602,21 @@ func (node arrayConverter[T]) convert(data interface{}) (interface{}, error) {

// TODO: convert sets

func handleXAutoClaimResponse(response *C.struct_CommandResponse) (*XAutoClaimResponse, error) {
func handleXAutoClaimResponse(response *C.struct_CommandResponse) (XAutoClaimResponse, error) {
defer C.free_command_response(response)
var null XAutoClaimResponse // default response
typeErr := checkResponseType(response, C.Array, false)
if typeErr != nil {
return nil, typeErr
return null, typeErr
}
slice, err := parseArray(response)
if err != nil {
return nil, err
return null, err
}
arr := slice.([]interface{})
len := len(arr)
if len < 2 || len > 3 {
return nil, &RequestError{fmt.Sprintf("Unexpected response array length: %d", len)}
return null, &RequestError{fmt.Sprintf("Unexpected response array length: %d", len)}
}
converted, err := mapConverter[[][]string]{
arrayConverter[[]string]{
Expand All @@ -628,11 +629,11 @@ func handleXAutoClaimResponse(response *C.struct_CommandResponse) (*XAutoClaimRe
false,
}.convert(arr[1])
if err != nil {
return nil, err
return null, err
}
claimedEntries, ok := converted.(map[string][][]string)
if !ok {
return nil, &RequestError{fmt.Sprintf("unexpected type of second element: %T", converted)}
return null, &RequestError{fmt.Sprintf("unexpected type of second element: %T", converted)}
}
var deletedMessages []string
deletedMessages = nil
Expand All @@ -642,41 +643,42 @@ func handleXAutoClaimResponse(response *C.struct_CommandResponse) (*XAutoClaimRe
false,
}.convert(arr[2])
if err != nil {
return nil, err
return null, err
}
deletedMessages, ok = converted.([]string)
if !ok {
return nil, &RequestError{fmt.Sprintf("unexpected type of third element: %T", converted)}
return null, &RequestError{fmt.Sprintf("unexpected type of third element: %T", converted)}
}
}
return &XAutoClaimResponse{arr[0].(string), claimedEntries, deletedMessages}, nil
return XAutoClaimResponse{arr[0].(string), claimedEntries, deletedMessages}, nil
}

func handleXAutoClaimJustIdResponse(response *C.struct_CommandResponse) (*XAutoClaimJustIdResponse, error) {
func handleXAutoClaimJustIdResponse(response *C.struct_CommandResponse) (XAutoClaimJustIdResponse, error) {
defer C.free_command_response(response)
var null XAutoClaimJustIdResponse // default response
typeErr := checkResponseType(response, C.Array, false)
if typeErr != nil {
return nil, typeErr
return null, typeErr
}
slice, err := parseArray(response)
if err != nil {
return nil, err
return null, err
}
arr := slice.([]interface{})
len := len(arr)
if len < 2 || len > 3 {
return nil, &RequestError{fmt.Sprintf("Unexpected response array length: %d", len)}
return null, &RequestError{fmt.Sprintf("Unexpected response array length: %d", len)}
}
converted, err := arrayConverter[string]{
nil,
false,
}.convert(arr[1])
if err != nil {
return nil, err
return null, err
}
claimedEntries, ok := converted.([]string)
if !ok {
return nil, &RequestError{fmt.Sprintf("unexpected type of second element: %T", converted)}
return null, &RequestError{fmt.Sprintf("unexpected type of second element: %T", converted)}
}
var deletedMessages []string
deletedMessages = nil
Expand All @@ -686,14 +688,14 @@ func handleXAutoClaimJustIdResponse(response *C.struct_CommandResponse) (*XAutoC
false,
}.convert(arr[2])
if err != nil {
return nil, err
return null, err
}
deletedMessages, ok = converted.([]string)
if !ok {
return nil, &RequestError{fmt.Sprintf("unexpected type of third element: %T", converted)}
return null, &RequestError{fmt.Sprintf("unexpected type of third element: %T", converted)}
}
}
return &XAutoClaimJustIdResponse{arr[0].(string), claimedEntries, deletedMessages}, nil
return XAutoClaimJustIdResponse{arr[0].(string), claimedEntries, deletedMessages}, nil
}

func handleXReadResponse(response *C.struct_CommandResponse) (map[string]map[string][][]string, error) {
Expand Down
8 changes: 4 additions & 4 deletions go/api/stream_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ type StreamCommands interface {
// [valkey.io]: https://valkey.io/commands/xlen/
XLen(key string) (int64, error)

XAutoClaim(key string, group string, consumer string, minIdleTime int64, start string) (*XAutoClaimResponse, error)
XAutoClaim(key string, group string, consumer string, minIdleTime int64, start string) (XAutoClaimResponse, error)

XAutoClaimWithOptions(
key string,
Expand All @@ -111,15 +111,15 @@ type StreamCommands interface {
minIdleTime int64,
start string,
options *options.XAutoClaimOptions,
) (*XAutoClaimResponse, error)
) (XAutoClaimResponse, error)

XAutoClaimJustId(
key string,
group string,
consumer string,
minIdleTime int64,
start string,
) (*XAutoClaimJustIdResponse, error)
) (XAutoClaimJustIdResponse, error)

XAutoClaimJustIdWithOptions(
key string,
Expand All @@ -128,7 +128,7 @@ type StreamCommands interface {
minIdleTime int64,
start string,
options *options.XAutoClaimOptions,
) (*XAutoClaimJustIdResponse, error)
) (XAutoClaimJustIdResponse, error)

XRead(keysAndIds map[string]string) (map[string]map[string][][]string, error)

Expand Down
8 changes: 4 additions & 4 deletions go/integTest/shared_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4178,7 +4178,7 @@ func (suite *GlideTestSuite) TestXAutoClaim() {
}
assert.Equal(
suite.T(),
&api.XAutoClaimResponse{
api.XAutoClaimResponse{
NextEntry: "0-2",
ClaimedEntries: map[string][][]string{
"0-1": {{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}},
Expand All @@ -4192,7 +4192,7 @@ func (suite *GlideTestSuite) TestXAutoClaim() {
assert.NoError(suite.T(), err)
assert.Equal(
suite.T(),
&api.XAutoClaimJustIdResponse{
api.XAutoClaimJustIdResponse{
NextEntry: "0-0",
ClaimedEntries: []string{"0-1", "0-2"},
DeletedMessages: deletedEntries,
Expand All @@ -4214,7 +4214,7 @@ func (suite *GlideTestSuite) TestXAutoClaim() {
assert.NoError(suite.T(), err)
assert.Equal(
suite.T(),
&api.XAutoClaimResponse{
api.XAutoClaimResponse{
NextEntry: "0-0",
ClaimedEntries: map[string][][]string{},
DeletedMessages: deletedEntries,
Expand All @@ -4226,7 +4226,7 @@ func (suite *GlideTestSuite) TestXAutoClaim() {
assert.NoError(suite.T(), err)
assert.Equal(
suite.T(),
&api.XAutoClaimJustIdResponse{
api.XAutoClaimJustIdResponse{
NextEntry: "0-0",
ClaimedEntries: []string{},
DeletedMessages: deletedEntries,
Expand Down

0 comments on commit 0d06f67

Please sign in to comment.