aboutsummaryrefslogtreecommitdiff
path: root/pkg/navitia_api_client/client.go
blob: aef8d0e12775c326aa22ee7cddf107655e1d4d0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package navitia_api_client

import (
	"fmt"
	"net/http"
	"sync"
	"time"
)

type Client struct {
	baseURL    string
	httpClient *http.Client

	mutex sync.Mutex
	cache map[string]cachedResult
}

type cachedResult struct {
	ts     time.Time
	result interface{}
}

func NewClient(token string) *Client {
	return &Client{
		baseURL: fmt.Sprintf("https://%s@api.sncf.com/v1", token),
		httpClient: &http.Client{
			Timeout: time.Minute,
		},
		cache: make(map[string]cachedResult),
	}
}