[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
|
@ -1,5 +1,11 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type AgentMessage struct {
|
||||
AccountID string `json:"accountId"`
|
||||
Credits int `json:"credits"`
|
||||
|
@ -9,6 +15,18 @@ type AgentMessage struct {
|
|||
Symbol string `json:"symbol"`
|
||||
}
|
||||
|
||||
func (c *Client) MyAgent() (APIMessage[AgentMessage, any], error) {
|
||||
return Send[AgentMessage](c, "GET", "/my/agent", nil)
|
||||
func (c *Client) MyAgent() (*AgentMessage, error) {
|
||||
uriRef := url.URL{Path: "my/agent"}
|
||||
msg, err := c.Send("GET", &uriRef, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if msg.Error != nil {
|
||||
return nil, msg.Error
|
||||
}
|
||||
var response AgentMessage
|
||||
if err := json.Unmarshal(msg.Data, &response); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal agent data: %w", err)
|
||||
}
|
||||
return &response, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue