Skip to content

rizalfadlila/golang_rest_api

Repository files navigation

Example Rest API

Setup Local Environment

Prerequisites

  • Git
  • Go (minimum 1.13 or above, make sure you set your local machine environment with GO111MODULE=on)
  • Docker compose
  • Docker
  • Mockgen
  • Swag

Installation

  • Clone this repository.

  • Run docker-compose to build the dependency docker instances:

$ docker-compose up --build
  • Make the environment files. Adjust your local configuration.
$ cp config.yaml.tpl .env
  • Run these commands to get all the app dependency's
$ swag i
$ go get -v ./...
  • Run the app. The app will run inside the local machine with exposed port configured in the env (by default: localhost:3030)
$ go run main.go

Development

Documentation

Access localhost:3030/swagger/index.html to read the API docs.

Migration

Reference to this doc to create a new migration file.

Mock an interface

Use mockgen to create a new mock. Tips: place mock file inside mocks directory

$ mockgen -package=mock -source=/path/to/interface/file -destination=/path/to/generated/mock/file

Add dependency

Use go mod as dependency tool.

$ go get github.com/gin-gonic/gin

Unit test

Use go test to run unit test.

$ go test -v -race -coverprofile=coverage.out -covermode=atomic ./...

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published