[golang] fixed golang api client design mistakes
This commit is contained in:
parent
d0f6c4343e
commit
0d00bf9fd2
9 changed files with 268 additions and 149 deletions
|
@ -6,18 +6,37 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// ----- 429 --------------------------------------------------------------------
|
||||
type RateLimitError struct {
|
||||
LimitType string `json:"type"`
|
||||
RetryAfter float64 `json:"retryAfter"`
|
||||
RetryAfter Duration `json:"retryAfter"`
|
||||
LimitBurst int `json:"limitBurst"`
|
||||
LimitPerSecond int `json:"limitPerSecond"`
|
||||
Remaining int `json:"remaining"`
|
||||
Reset time.Time `json:"reset"`
|
||||
}
|
||||
|
||||
func decode429(msg []byte) (e APIMessage[any, RateLimitError]) {
|
||||
func decodeRateLimitError(msg json.RawMessage) RateLimitError {
|
||||
var e RateLimitError
|
||||
if err := json.Unmarshal(msg, &e); err != nil {
|
||||
panic(fmt.Sprintf("Failed to decode419: %+v", err))
|
||||
panic(fmt.Errorf("Failed to decode iapi error code 429 RateLimitError: %v, %w", msg, err))
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
// ----- 4214 -------------------------------------------------------------------
|
||||
type ShipInTransitError struct {
|
||||
Arrival time.Time `json:"arrival"`
|
||||
DepartureSymbol string `json:"departureSymbol"`
|
||||
DepartureTime time.Time `json:"departureTime"`
|
||||
DestinationSymbol string `json:"destinationSymbol"`
|
||||
SecondsToArrival Duration `json:"secondsToArrival"`
|
||||
}
|
||||
|
||||
func decodeShipInTransitError(msg json.RawMessage) ShipInTransitError {
|
||||
var e ShipInTransitError
|
||||
if err := json.Unmarshal(msg, &e); err != nil {
|
||||
panic(fmt.Errorf("Failed to decode api error code 4214 ShipInTransitError: %v, %w", msg, err))
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue