go-boilerplate

module
v0.0.0-...-40cab1b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2023 License: Apache-2.0

README

Boilerplate

Code structure

How to develop
Tool installation
$ go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
$ go install github.com/cosmtrek/air@latest
$ go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
$ go install github.com/swaggo/swag/cmd/swag@latest
Basic
# make sure you have dependencies up
$ docker compose up -d

# manual run
$ go run cmd/app/main.go

# hot reloading
$ air
Swagger

Please note that it's only for local environment

Served at: http://localhost:8080/swagger/index.html

$ swag init -d api,internal/request,internal/response,internal/database/entities -o ./api/docs -g ./http.go
Authentication

In local development, we send email in 'authorization' header

In development, uat and production environment, we use jwt auth

# local
$ curl localhost:8080/... -H 'authorization: admin@example.com'

# development, uat, production
$ curl localhost:8080/... -H 'authorization: Bearer ...'
Linter

❗️Please do this before raise the PRs ❗️

$ make lint
DAO Interface generation

❗️Please do this when you have updated the entities ❗️

$ go run cmd/gen/main.go
Migration

New migration, find out more on best practices here

$ migrate create -digits 6 -dir migrations -ext sql -seq 'MIGRATION_NAME'

For testing only, in the code we have auto-migration in place.

$ migrate -source file://migrations -database 'postgres://service:password@localhost:5432/book?sslmode=disable' up
$ migrate -source file://migrations -database 'postgres://service:password@localhost:5432/book?sslmode=disable' down -all
$ migrate -source file://migrations -database 'postgres://service:password@localhost:5432/book?sslmode=disable' drop -f
Test
# make sure you have dependencies up
$ docker compose up -d

$ make test

Directories

Path Synopsis
api
docs
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.
cmd
app
gen
internal
app

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL