diff options
author | Julien Dessaux | 2021-04-05 17:52:31 +0200 |
---|---|---|
committer | Julien Dessaux | 2021-04-05 17:52:31 +0200 |
commit | 1ffc9c42054e208a01d3e70e6b6f3e1781e798f8 (patch) | |
tree | 721f202dcf46fb5e9c181013237e4da9d27f796a /pkg/navitia_api_client/client.go | |
parent | Reworked error handling for better and simpler tests (diff) | |
download | trains-1ffc9c42054e208a01d3e70e6b6f3e1781e798f8.tar.gz trains-1ffc9c42054e208a01d3e70e6b6f3e1781e798f8.tar.bz2 trains-1ffc9c42054e208a01d3e70e6b6f3e1781e798f8.zip |
Moved code around to conform best practices
Diffstat (limited to 'pkg/navitia_api_client/client.go')
-rw-r--r-- | pkg/navitia_api_client/client.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/pkg/navitia_api_client/client.go b/pkg/navitia_api_client/client.go new file mode 100644 index 0000000..aef8d0e --- /dev/null +++ b/pkg/navitia_api_client/client.go @@ -0,0 +1,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), + } +} |