A Go implementation of an API Test CRM service.
go run monkey.go
- Learn Go
- Implement an API from scratch
- Get to know the popular
gin
web framework - Set up authorization with OAuth 2.0
- Exchange auth token with Google
- Check if the ID token is a valid JWT
- Avoid ORM libraries like GORM
- Write raw SQL for schemas and queries
- Get to know
sqlc
to compile SQL to type-safe code - Set up postgres running in podman
- Use
golang-migrate
to generate migrations
- SQL schema defines the Customer and User models
query.sql
defines the model relationssqlc.yml
config file references the schema and query, along with the database engine and output files that will be generatedsqlc
generates Go structs that will be used in the Go program to interface with the database. These structs are type safe and protect against SQL injections- Various
.sh
scripts document how to run commands that set up the database - Containerized postgres runs on
podman
machine golang-migrate
generates migrations- Seed function populates the database initially
gin
for handling routes- Handlers specify User and Customer routes
- Model structs are used in route actions, as a form of ORM
- Queries and auth middleware added to
gin
context
- Set up project on Google Cloud Console, get client id and secret, set as ENV variables
- Inject auth middleware into
gin
context for specific routes - Auth route handler handles the callback after authorization, gets id token and sets it in a cookie
- Auth middleware validates the id token and sets User as admin