Core Gin with Gin Web Framework
- Application backbone with Gin Web Framework
- Dependency injection using uber-go/fx
- API endpoints documentation with swag
- Uses fully featured GORM
- Agent OpenTelemetry-Go
- Metric go-http-metrics
- Setup environment variables
cp .env.example .env- Update your database credentials environment variables in
.envfile
- Run
go run main.go app:serveto start the server. - There are other commands available as well. You can run
go run main.go -helpto know about other commands available.
| Folder Path | Description |
|---|---|
/api |
contains all the middlwares, and routes of the server in their respective folders |
/bootstrap |
contains modules required to start the application |
/commands |
server commands |
/constants |
global application constants |
/docs |
API endpoints documentation using swagger |
/infrastructure |
third-party services connections like postgress, otel, slack, ... |
/lib |
contains library code |
/migration |
database migration files |
/internal/dto |
Data Transfer Object. such as Request and response Model |
/internal/handler |
handler layer it's such as controller to handle routes endpoint |
/internal/models |
ORM models |
/internal/repositories |
contains repository. Mainly database queries are added here. |
/internal/services |
service layers, contains the functionality that compounds the core of the application |
/utils |
global utility/helper functions |
.env.example |
sample environment variables |
dbconfig.yml |
database configuration file for sql-migrate command |
main.go |
entry-point of the server |
Makefile |
stores frequently used commands; can be invoked using make command |
⚓️ If you want to run the migration runner from the host environment instead of the docker environment; ensure that sql-migrate is installed on your local machine.
You can skip this step if
sql-migratehas already been installed on your local machine.
Note: Starting in Go 1.17, installing executables with go get is deprecated. go install may be used instead. Read more
go install github.com/rubenv/sql-migrate/...@latestIf you're using Go version below 1.18
go get -v github.com/rubenv/sql-migrate/...Available migration commands
| Command | Desc |
|---|---|
make migrate-status |
Show migration status |
make migrate-up |
Migrates the database to the most recent version available |
make migrate-down |
Undo a database migration |
make migrate-redo |
Reapply the last migration |
make migrate-create |
Create new migration file |
The framework comes with unit and integration testing support out of the box. You can check examples written in tests directory.
To run the test just run:
go test ./... -vgo test ./... -v -coverprofile cover.txt -coverpkg=./...
go tool cover -html=cover.txt -o index.htmlYou can skip this step if
gopherbadgerhas already been installed on your local machine.
install the executeable (ensure your $PATH contains $GOPATH/bin):
go install github.com/jpoles1/gopherbadger@latest
Available generate badge commands
| Command | Desc |
|---|---|
make generate-cover |
Generate Coverage Badge on README |
You can skip this step if
swaghas already been installed on your local machine.
- Download swag by using:
go install github.com/swaggo/swag/cmd/swag@latest- Add comments to your API source code, See Declarative Comments Format.
Available generate commands
| Command | Desc |
|---|---|
make generate-docs |
Generate Documentation On Declarative Comments Format |
To See Doc run the app and Browse to http://localhost/swagger/index.html
- You can see all the documented endpoints in Swagger-UI from the API specification