A production ready base template for GoLang REST using Gin
developer note: you can use any other DB config by changing the implementation under db/database.go
Building the application
$ go build -o bin/restapi main.go
Seeding the database
$ go run db/seed.go
$ go run main.go
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/...
Documentation can be accessed via http://localhost:8080/v1/api-docs
Swagger documentation via code comment and autogenerated using swaggo. Run the command below to generate documentation
$ swag init
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
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