diff options
author | Julien Dessaux | 2024-05-30 08:05:03 +0200 |
---|---|---|
committer | Julien Dessaux | 2024-05-30 08:05:03 +0200 |
commit | 4069b524b2c607dcf8fc1e378ae86077f8a89234 (patch) | |
tree | 3e42383cafb4a7f24252d4bc55b2481c3f9b014d /golang/pkg/api/register.go | |
parent | [golang] added ships first api calls (diff) | |
download | spacetraders-4069b524b2c607dcf8fc1e378ae86077f8a89234.tar.gz spacetraders-4069b524b2c607dcf8fc1e378ae86077f8a89234.tar.bz2 spacetraders-4069b524b2c607dcf8fc1e378ae86077f8a89234.zip |
[golang] simplified the api design some more
Diffstat (limited to '')
-rw-r--r-- | golang/pkg/api/register.go | 27 |
1 files changed, 7 insertions, 20 deletions
diff --git a/golang/pkg/api/register.go b/golang/pkg/api/register.go index 4f45cd1..d6c185c 100644 --- a/golang/pkg/api/register.go +++ b/golang/pkg/api/register.go @@ -1,38 +1,25 @@ package api import ( - "encoding/json" - "fmt" "net/url" -) -type RegisterMessage struct { - //agent - //contract - //faction - //ship - Token string `json:"token"` -} + "git.adyxax.org/adyxax/spacetraders/v2/pkg/model" +) -func (c *Client) Register(faction, symbol string) (*RegisterMessage, error) { +func (c *Client) Register(faction, symbol string) (*model.Register, error) { type RegisterRequest struct { Faction string `json:"faction"` Symbol string `json:"symbol"` } uriRef := url.URL{Path: "register"} - msg, err := c.Send("POST", &uriRef, RegisterRequest{ + payload := RegisterRequest{ Faction: faction, Symbol: symbol, - }) + } + var response model.Register + err := c.Send("POST", &uriRef, payload, &response) if err != nil { return nil, err } - if msg.Error != nil { - return nil, msg.Error - } - var response RegisterMessage - if err := json.Unmarshal(msg.Data, &response); err != nil { - return nil, fmt.Errorf("failed to unmarshal register data: %w", err) - } return &response, nil } |