Skip to content

felguerez/server-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

server-api

Building a monolithic API backend with Golang. I'm using gofiber/fiber as a web framework, which looks a lot like Express.

Getting started

Time to set up web-service!

Prerequisites

Environment

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.

Golang

This project uses Go v1.20.3. You can find installation instructions at go.dev or install with homebrew:

brew install go

AWS/DynamoDB

You 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.

Spotify Web API

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.

Gmail App Password

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.

Installation and setup (development)

  1. Clone the repo:
$ git clone git@github.com:felguerez/server-api.git
  1. Sync dependencies:
$ cd server-api/
$ go get .
  1. Rename .env.example to .env:
$ mv .env.example .env
  1. Create a DynamoDB table and copy the name to .env as TABLE_NAME
  2. Create an app at developer.spotify.com and copy the client id and client secret to .env as SPOTIFY_CLIENT_ID and SPOTIFY_CLIENT_SECRET respectively.
  3. Build the project:
$ go build
  1. 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
  1. Congrats! 🍾 You've got an app running on http://localhost:3000. You can also view the API docs at http://localhost:3000/swagger.

Deployment

This project deploys continuously via Google Cloud Run:

TODO

  • Register a domain
  • Deploy a client

About

Messing around with Golang/Fiber

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published