Skip to content

Commit

Permalink
Adjust Go code to new lib.h
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-congo committed Mar 21, 2024
1 parent 05f1ae0 commit 7aad421
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 3 additions & 2 deletions go/api/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ func createClient(converter connectionRequestConverter) (*baseClient, error) {
)
defer C.free_connection_response(cResponse)

cErr := cResponse.error_message
cErr := cResponse.connection_error_message
if cErr != nil {
return nil, goError(cResponse.error_type, cResponse.error_message)
message := C.GoString(cErr)
return nil, &ConnectionError{message}
}

return &baseClient{cResponse.conn_ptr}, nil
Expand Down
6 changes: 6 additions & 0 deletions go/api/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ package api
// #include "../lib.h"
import "C"

type ConnectionError struct {
msg string
}

func (e *ConnectionError) Error() string { return e.msg }

// RequestError is a Redis client error that occurs when an error is reported during a request.
type RequestError struct {
msg string
Expand Down
2 changes: 1 addition & 1 deletion go/integTest/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ func (suite *GlideTestSuite) TestConnectWithInvalidAddress() {

assert.Nil(suite.T(), client)
assert.NotNil(suite.T(), err)
assert.IsType(suite.T(), &api.DisconnectError{}, err)
assert.IsType(suite.T(), &api.ConnectionError{}, err)
}

0 comments on commit 7aad421

Please sign in to comment.