8000 GitHub - erwan690/core-gin · GitHub
[go: up one dir, main page]

Skip to content
erwan690Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

Core Gin

gopherbadger-tag-do-not-edit

Core Gin with Gin Web Framework

Features

Run application

  • Setup environment variables
cp .env.example .env
  • Update your database credentials environment variables in .env file

Locally

  • Run go run main.go app:serve to start the server.
  • There are other commands available as well. You can run go run main.go -help to know about other commands available.

Folder Structure 📁

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

Migration Commands

⚓️   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.

Install sql-migrate

You can skip this step if sql-migrate has 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/...@latest

If you're using Go version below 1.18

go get -v github.com/rubenv/sql-migrate/...

Running migration

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

Testing

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 ./... -v

For test coverage

go test ./... -v -coverprofile cover.txt -coverpkg=./...
go tool cover -html=cover.txt -o index.html

For coverage Badge

You can skip this step if gopherbadger has already been installed on your local machine.

install the executeable (ensure your $PATH contains $GOPATH/bin):

go install github.com/jpoles1/gopherbadger@latest

Running generation Bade

Available generate badge commands
Command Desc
make generate-cover Generate Coverage Badge on README

API documents with SWAG

You can skip this step if swag has already been installed on your local machine.

  • Download swag by using:
go install github.com/swaggo/swag/cmd/swag@latest

Running generation

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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

0