From 40c4a8df155f7be75e34498ec538ac2eca5097bd Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 20 Feb 2025 08:12:57 +0100 Subject: [golang] refactored the api client to reduce the amount of db pointer shuffling around --- golang/pkg/api/client.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'golang/pkg/api/client.go') diff --git a/golang/pkg/api/client.go b/golang/pkg/api/client.go index 2ea555e..e6a1883 100644 --- a/golang/pkg/api/client.go +++ b/golang/pkg/api/client.go @@ -6,10 +6,13 @@ import ( "net/http" "net/url" "time" + + "git.adyxax.org/adyxax/spacetraders/golang/pkg/database" ) type Client struct { baseURI *url.URL + db *database.DB requestsChannel chan *Request ctx context.Context headers *http.Header @@ -17,7 +20,7 @@ type Client struct { pq *PriorityQueue } -func NewClient(ctx context.Context) *Client { +func NewClient(ctx context.Context, db *database.DB) *Client { baseURI, err := url.Parse("https://api.spacetraders.io/v2/") if err != nil { panic("baseURI failed to parse") @@ -26,6 +29,7 @@ func NewClient(ctx context.Context) *Client { heap.Init(&pq) client := &Client{ baseURI: baseURI, + db: db, requestsChannel: make(chan *Request), ctx: ctx, headers: &http.Header{ -- cgit v1.2.3