Building a monolithic API backend with Golang. I'm using gofiber/fiber as a web framework, which looks a lot like Express.
Time to set up web-service!
Before you get the project running you'll need to configure your environment. The app uses dotenv to autoload values defined in .env. You can also pass these values as environment variables when running the app if you prefer.
This project uses Go v1.20.3. You can find installation instructions at go.dev or
install with homebrew:
brew install goYou should have an AWS account with access keys (AWS_SECRET_ACCESS_KEY, AWS_SECRET_KEY_ID) stored in .env. You'll need AWS for storage using DynamoDB.
After creating a DynamoDB table, add the table name to .env.
This project also uses the Spotify Web API. You'll need to create an app at Spotify for Developers. Add your app's client ID and client secret to the .env file.
This project sends email via SMTP authenticated through Gmail App Passwords. You can send emails through your own Gmail
account by setting up an App Password which is available if you
have 2FA enabled on your Google account. After generating an App Password in your Google Account under the Security
settings, add it to .env as SMTP_PASSWORD, along with your Gmail address as SMTP_USERNAME.
- Clone the repo:
$ git clone git@github.com:felguerez/server-api.git- Sync dependencies:
$ cd server-api/
$ go get .- Rename
.env.exampleto.env:
$ mv .env.example .env- Create a DynamoDB table and copy the name to
.envasTABLE_NAME - Create an app at developer.spotify.com and copy the client id and client
secret to
.envasSPOTIFY_CLIENT_IDandSPOTIFY_CLIENT_SECRETrespectively. - Build the project:
$ go build- Run 🏃♂️ (note the module name is
web-service):
$ go run web-service Pro-tip: You can run the project with air for nodemon-style live reloading:
$ go install github.com/cosmtrek/air@latest
$ echo -e "\nalias air=$(go env GOPATH)/bin/air"
$ air # runs and reloads the app using .air.toml config- Congrats! 🍾 You've got an app running on http://localhost:3000. You can also view the API docs at http://localhost:3000/swagger.
This project deploys continuously via Google Cloud Run:
- 🔗 root index
- 🔗
/api/spotify/recently-played - 🔗
/api/spotify/currently-playing - 🔗
/api/spotify/top/artists - 🔗
/api/spotify/top/tracks
- Register a domain
- Deploy a client