[golang] refactored the api client to reduce the amount of db pointer shuffling around
This commit is contained in:
parent
312ef2eb57
commit
40c4a8df15
9 changed files with 58 additions and 57 deletions
|
@ -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{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue