Skip to content

misterpuffin/go-rest-api-boilerplate

Repository files navigation

Golang Rest API Boilerplate

CI CI

Boilerplate API built using Golang: (Gin Framework for routing, Testify for testing, Swagger for Documentation, Viper for configuration, and Go Mod for dependency management). The intention is for this to be used as a starter application to build out a scalable and organized API service. With minimal configuration, this application can be built and deployed in a container using docker. We have done some research and have tried to stick to Golang best practices as much as possible. The routes and testing can be expanded to meet your needs.

🚀 Quick start

  1. Start coding!

    You should now be able to start coding. You can start expanding, building, and deploying. You can use make to build/ run your app:

     make build
     make run
    

🧐 What's inside?

A quick look at the top-level files and directories you'll see in this project.

.
├── build/
├── config/
├── docs/
├── internal/
├── sql/
├── Dockerfile
├── docker-compose.yaml
├── Makefile
├── go.mod
├── go.sum
├── main.go
├── sqlc.yaml
├── .gitignore
└── README.md
  1. /build: This directory contains the binary after a build

  2. /config: This directory contains the viper configration and the property files.

  3. /docs: Directory for swagger files.

  4. /internal: This directory contains all the go code for the project.

  5. /sql: This directory contains all the sql files for the project (migrations/sqlc queries).

  6. Dockerfile: This file contains the buildsteps to build your image using a multi stage build. It is currently using a scratch image to keep it lightweight.

  7. docker-compose.yaml: This file contains the docker-compose configurations for easy set-up of a local dev environment.

  8. Makefile: This file allows the use of make to run tests, build locally, and is used to build in the pipeline. This can be expanded as needed

  9. go.mod/go.sum: These files are generated by Go Mod dependency management and can be learned about in the documentation link provided above.

  10. main.go: This file is the starting point for the application, which starts the server.

  11. sqlc.yaml: This file is the config file for sqlc, which determines where the .sql code in /sql gets generated to.

  12. .gitignore: This file tells git which files it should not track / not maintain a version history for.

  13. README.md: A text file containing useful reference information about your project.

🛢️ Database

Migrations

This project uses goose to manage database migrations. Simply add new migrations into the sql/migrations folder and run make migrate_up or make migrate_down.

  • For more specialised use, please refer to goose documentation

Queries

This project uses sqlc to generate type-safe golang code from SQL.

  • All queries go into the sql/queries folder.
  • Run sqlc generate to generate golang code for your SQL queries. All code is generated into the internal/db/sqlc folder

🎓 Further Changes

There may be further configuration needed as you expand your application.

Contributors:

  • Sng Haoren

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages