Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/syahidfrd/go-boilerplate
REST API boilerplate built with Go - Echo Framework
https://github.com/syahidfrd/go-boilerplate
boilerplate echo-framework go golang jwt migration mockery postgres postgresql redis rest-api swagger testify unit-test zerolog
Last synced: about 2 hours ago
JSON representation
REST API boilerplate built with Go - Echo Framework
- Host: GitHub
- URL: https://github.com/syahidfrd/go-boilerplate
- Owner: syahidfrd
- License: mit
- Created: 2021-10-03T00:28:23.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-03-03T00:29:41.000Z (over 1 year ago)
- Last Synced: 2024-11-16T03:19:50.883Z (4 days ago)
- Topics: boilerplate, echo-framework, go, golang, jwt, migration, mockery, postgres, postgresql, redis, rest-api, swagger, testify, unit-test, zerolog
- Language: Go
- Homepage: https://pkg.go.dev/github.com/syahidfrd/go-boilerplate
- Size: 94.7 KB
- Stars: 35
- Watchers: 2
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GO Boilerplate
[![Go Reference](https://pkg.go.dev/badge/github.com/andhikayuana/qiscus-unofficial-go.svg)](https://pkg.go.dev/github.com/syahidfrd/go-boilerplate)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Go Report Card](https://goreportcard.com/badge/github.com/andhikayuana/qiscus-unofficial-go)](https://goreportcard.com/report/github.com/syahidfrd/go-boilerplate)### Directory Structure
```
├── cmd
│ └── api // Main applications for this project
├── config // Configuration app
├── delivery // Delivery usefull to encode raw body, query params, make a response to client
│ ├── http
│ └── middleware
├── docs // Design and user documents (in addition to your godoc generated documentation)
├── domain // Domains is a struct to store any objects from database, example you have a products in your tables.
├── infrastructure
│ └── datastore // Database configuration
├── migration // Database migrations.
├── mocks // Mock code, generated by mockery
├── repository // Represents the behavior of the data store. It can be implemented using PostgreSQL, MongoDB, etc
│ ├── pgsql
│ └── redis
├── transport // Request and response model
│ └── request
├── usecase // Usecase contains all of business logic
└── utils // Additional services
├── crypto
├── jwt
```### Prerequisite and full list what has been used
* [PostgreSQL](https://www.postgresql.org) - PostgreSQL Database
* [Redis](https://redis.com) - Redis
* [golang-migrate](https://github.com/golang-migrate/migrate) - Database migrations. CLI and Golang library
* [echo](https://github.com/labstack/echo) - Web framework
* [go-redis](https://github.com/go-redis/redis) - Type-safe Redis client for Golang
* [zerolog](https://github.com/rs/zerolog) - Logger
* [ozzo-validation](https://github.com/go-ozzo/ozzo-validation) - Go Struct and Field validation
* [mockery](https://github.com/vektra/mockery) - A mock code autogenerator for Golang
* [swag](https://github.com/swaggo/swag) - Generator RESTful API documentation with Swagger
* [echo-swagger](https://github.com/swaggo/echo-swagger) - Echo middleware for Swagger
* [testify](https://github.com/stretchr/testify) - A toolkit with common assertions and mocks
* [godotenv](https://github.com/joho/godotenv) - Environment variables loaderApp requires 2 database (PostgreSQL and Redis server), run from your local machine or run it using docker with the following command
```
# run postgreSQL
docker run -d -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=go_boilerplate postgres# run redis
docker run -d -p 6379:6379 redis
```### Migration
Run below command to run migration
```
migrate -path migration -database "${DATABASE_URL}" up
```To create a new migration file
```
migrate create -ext sql -dir migration -seq name
```### Test
Run below command to run test, and make sure that all tests are passing
```
go test -v ./...
```### Running
Run below command to run app
```
go run ./cmd/api/main.go
```Swagger URL
```
${BASE_URL}/swagger/index.html
```You can find usefull commands in `Makefile`.