1.4 KiB
Basic spotify API in golang
This API supports simple artist read operations for spotify data, as well as using a simple caching database and handling client authentication automatically.
Setup
After compiling the binary, or when executing via go run
, just be sure to set the following environment variables to enable access to Spotify's API
SPOTIFY_ID=<your spotify client ID>
SPOTIFY_TOKEN=<your spotify token>
Example execution using the linux command line:
SPOTIFY_ID=myspotifyID SPOTIFY_TOKEN=myspotifytoken ./gomusic
Alternatively you can use go run
too:
SPOTIFY_ID=myspotifyID SPOTIFY_TOKEN=myspotifytoken go run .
Testing
This application comes with a complete test suite, it can be run using the standard go test
system
When running tests you are required to provide the same credentials as when running the server normally.
For example:
SPOTIFY_ID=myspotifyID SPOTIFY_TOKEN=myspotifytoken go test .
Technical Choices
This project is built using the Gin framework, for easy and consistent request contexts, as well as easy to expand middleware support. For database interactions it uses the gorm library, to allow for advanced SQL features and server agnostic support.
This API currently uses sqlite as the database for simplicity, but switching to postgres or mysql is easy without any loss of functionality or change in database calls.