api-structs #117
@ -11,7 +11,7 @@ var (
|
||||
|
||||
// LoadConfig initializes the configuration values after environment variables are loaded.
|
||||
func LoadConfig() {
|
||||
CreateAccountURL = initializers.GetEnv("CREATE_ACCOUNT_URL", "http://localhost:5003/api/v2/account/create")
|
||||
CreateAccountURL = initializers.GetEnv("CREATE_ACCOUNT_URL", "http://localhost:5003/api/v2/account/creates")
|
||||
TrackStatusURL = initializers.GetEnv("TRACK_STATUS_URL", "https://custodial.sarafu.africa/api/track/")
|
||||
BalanceURL = initializers.GetEnv("BALANCE_URL", "https://custodial.sarafu.africa/api/account/status/")
|
||||
TrackURL = initializers.GetEnv("TRACK_URL", "http://localhost:5003/api/v2/account/status")
|
||||
|
@ -14,9 +14,8 @@ import (
|
||||
)
|
||||
|
||||
|
||||
var (
|
||||
okResponse api.OKResponse
|
||||
errResponse api.ErrResponse
|
||||
EMPTY_RESPONSE = 0
|
||||
okResponse api.OKResponse
|
||||
errResponse api.ErrResponse
|
||||
)
|
||||
|
||||
type AccountServiceInterface interface {
|
||||
@ -93,7 +92,7 @@ func (as *AccountService) TrackAccountStatus(publicKey string) (*api.OKResponse,
|
||||
}
|
||||
return nil, errors.New(errResponse.Description)
|
||||
}
|
||||
if len(okResponse.Result) == EMPTY_RESPONSE {
|
||||
if len(okResponse.Result) == 0 {
|
||||
return nil, errors.New("Empty api result")
|
||||
lash
commented
I would just use the literal I would just use the literal `0` here
kamikazechaser
commented
If there is no matching tracking id, result.otx will be null. If there is no matching tracking id, result.otx will be null.
lash
commented
@kamikazechaser please elaborate is there a missing case? @kamikazechaser please elaborate is there a missing case?
|
||||
}
|
||||
return &okResponse, nil
|
||||
@ -150,6 +149,7 @@ func (as *AccountService) CreateAccount() (*api.OKResponse, error) {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal([]byte(body), &okResponse)
|
||||
|
||||
if err != nil {
|
||||
err := json.Unmarshal([]byte(body), &errResponse)
|
||||
if err != nil {
|
||||
@ -157,7 +157,7 @@ func (as *AccountService) CreateAccount() (*api.OKResponse, error) {
|
||||
}
|
||||
return nil, errors.New(errResponse.Description)
|
||||
}
|
||||
if len(okResponse.Result) == EMPTY_RESPONSE {
|
||||
if len(okResponse.Result) == 0 {
|
||||
return nil, errors.New("Empty api result")
|
||||
}
|
||||
return &okResponse, nil
|
||||
|
Loading…
Reference in New Issue
Block a user
why is this needed?
Well,at the point of making the api call and receiving a response back, we don't really know the response that will be sent back,it can either be an ErrResponse or an OKResponse but we are certain that the ok and description field will be present.So the OK field in the ApiResponse will be used to decide which type to Unmarshal on.