1
0
Fork 0

[golang] refactored the api client to reduce the amount of db pointer shuffling around

This commit is contained in:
Julien Dessaux 2025-02-20 08:12:57 +01:00
parent 312ef2eb57
commit 40c4a8df15
Signed by: adyxax
GPG key ID: F92E51B86E07177E
9 changed files with 58 additions and 57 deletions

View file

@ -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{