Move backend to subdir
[brackets.git] / backend / client / client.go
1 package client
2
3 import (
4 "context"
5 "fmt"
6 "github.com/zmb3/spotify"
7 "golang.org/x/oauth2/clientcredentials"
8 "os"
9 )
10
11 func Get() (*spotify.Client, error) {
12 config := &clientcredentials.Config{
13 ClientID: os.Getenv("SPOTIFY_ID"),
14 ClientSecret: os.Getenv("SPOTIFY_SECRET"),
15 TokenURL: spotify.TokenURL,
16 }
17
18 token, err := config.Token(context.Background())
19 if err != nil {
20 return nil, fmt.Errorf("client: %w", err)
21 }
22
23 client := spotify.Authenticator{}.NewClient(token)
24 client.AutoRetry = true
25 return &client, nil
26 }