Skip to content

A go api base project with all best practices I learned over the years

Notifications You must be signed in to change notification settings

maxwelbm/go-api-study

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go API

This repository contains all best practices for writing a go API that I learned over the years. It is meant to be cloned and renamed to get a headstart for building out your api. Or just to be pulled up while working on another project to find inspiration.

This repo uitlizes

  • Command line flags using pflag
  • Structured logging using zap
  • HTTP framework using chi
  • Database integration using gorm
  • Database integration tests using dockertest
  • API integration tests using gomock
  • Documentation as code using http-swagger

And follows the following best practices:

  • Log version on startup
  • Graceful exit
  • Staged Dockerfile
  • Custom middlewares
  • Swagger docs

Run

To run this api you need a postgres instance. You can set the connection string via the DB_CONNECTION environment variable. The following command starts an empty database and calls runs the binary:

make run

Make it Your Own

Clone this repo with

git clone https://github.com/jonnylangefeld/go-api.git

And rename the module with

go mod edit -module <your module name>

About

A go api base project with all best practices I learned over the years

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 95.6%
  • Makefile 2.8%
  • Dockerfile 1.6%