The fastest way to build a restful API with golang and echo framework. Includes common required features for modern web applications. A boilerplate project with golang and Echo.
The fastest way to build a restful api with Echo with a structured project that using PostgreSQL db and JWT base authentication middleware.
This project ships following features as default
Inspired from Gin boilerplate.
$ go get github.com/triaton/go-echo-boilerplate
$ cd $GOPATH/src/github.com/triaton/go-echo-boilerplate
$ go mod init
$ go install
Rename .env.example to .env and place your database credentials and jwt secret key
$ mv .env.example .env
$ go run main.go
$ go build -v
$ ./go-echo-boilerplate
$ go test -v ./...
$ chmod +x generate-test-coverage.sh
$ ./generate-test-coverage.sh
This will generate cover.html
with detailed coverage result.
$ mockery --all --keep-tree
For more information please visit this link.
To add a controller
*_controller.go
fileauth/auth_controller.go
.routes/api.go
...
func DefineApiRoute(e *echo.Echo) {
controllers := []common.Controller{
auth.AuthController{},
blogs.BlogsController{},
// add newly added controller here
}
var routes []common.Route
...
To add a service
*_service.go
file.set
method. It will be used when mocking service methods.To add db models
models
and define *.model.go
file.models.Base
. Please refer blogs/models/blog.model.go
.Edit database/migrations.go
to add a new migration. For detailed guide, please visit this link.
Download Postman -> Import -> Import From Link https://www.getpostman.com/collections/401dc48dd6e9b15cc287
You are welcome to contribute to keep it up to date and always improving!
(The MIT License)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.