From 5ee0fb4aa53e02a4b6c2ffb3d5bfa3a6153c9a06 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sun, 21 May 2023 20:05:01 +0200 Subject: implement YAML config and admin connections --- spotify.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'spotify.go') diff --git a/spotify.go b/spotify.go index 8a32fc6..0e4974a 100644 --- a/spotify.go +++ b/spotify.go @@ -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 } -- cgit v1.2.3