diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-05-21 20:05:01 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2023-05-21 20:05:01 +0200 |
| commit | 5ee0fb4aa53e02a4b6c2ffb3d5bfa3a6153c9a06 (patch) | |
| tree | 5268e39568e6146521e4be9e0c1b70d3afca538c /spotify.go | |
| parent | ead811a4ebd0074cc4d42da53daacbb358229fac (diff) | |
| download | WRMS-5ee0fb4aa53e02a4b6c2ffb3d5bfa3a6153c9a06.tar.gz WRMS-5ee0fb4aa53e02a4b6c2ffb3d5bfa3a6153c9a06.zip | |
implement YAML config and admin connections
Diffstat (limited to 'spotify.go')
| -rw-r--r-- | spotify.go | 21 |
1 files changed, 14 insertions, 7 deletions
@@ -25,23 +25,30 @@ const ( deviceName = "wrms" ) +type spotifyConfig struct { + username string + password string +} + type SpotifyBackend struct { session *core.Session } -func NewSpotify() (*SpotifyBackend, error) { +func NewSpotify(config *spotifyConfig) (*SpotifyBackend, error) { spotify := SpotifyBackend{} + if config != nil { + config = &spotifyConfig{} + } - var err error + config.username = os.Getenv("WRMS_SPOTIFY_USER") + config.password = os.Getenv("WRMS_SPOTIFY_PASSWORD") - username := os.Getenv("WRMS_SPOTIFY_USER") - password := os.Getenv("WRMS_SPOTIFY_PASSWORD") - if username == "" || password == "" { + if config.username == "" || config.password == "" { return nil, errors.New("User and password for spotify must be provided") } - spotify.session, err = librespot.Login(username, password, deviceName) - + var err error + spotify.session, err = librespot.Login(config.username, config.password, deviceName) if err != nil { return nil, err } |
