Skip to content

sutjin/go-rest-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-rest-template

A production ready base template for GoLang REST using Gin

Requirement

developer note: you can use any other DB config by changing the implementation under db/database.go

Installation

Building the application

$ go build -o bin/restapi main.go

Seeding the database

$ go run db/seed.go

Run Local

$ go run main.go

Running Unit Test

A local database needs to be installed in your computer with the right credential and test DB to be configured under /test/init_test.go

run the test with

$ go test -v ./test/...

API Documentation

Documentation can be accessed via http://localhost:8080/v1/api-docs

Auto Generate Swagger

Swagger documentation via code comment and autogenerated using swaggo. Run the command below to generate documentation

$ swag init

Running as Docker

Run the app as a Docker container by using the command below. dev environment will copy the code over as a whole to allow unit testing while prod environment is a compiled Go project with lower footprint.

dev env

$ docker build --target builder -t SOME_SERVICE:dev .

prod env

$ docker build -t SOME_SERVICE .

Run your image via

$ docker container run SOME_SERVICE:dev

or 

$ docker container run SOME_SERVICE

Akses via http://<docker_ip>:8080

Additional Note

If you are interested in building this via a pipeline using Github (with unit test integration), you can follow along with here:

Using A Database for Unit Testing With Docker in GitLab Pipeline

About

A base template for GoLang REST using Gin

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published