Skip to content

r0b6/gin-microservice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gin Microservice Example

Version: 0.1.0

Example microservice using the Go Gin framework

Main libraries

  • Gin - API Router, controllers
  • Gom - Package management
  • Viper - Configuration
  • Stew - Extends common Go objects providing better alternatives or wrappers

Test libraries

  • Testify - Testing framework
  • Mock - Mock underlying HTTP request/responses

Create an API key

  • Go to OpenWeatherMap.org, sign up and copy the api key
  • Uncomment the following line in config/development.toml
#app_id = "put-your-api-key-here"
  • Remove the leading hash character and replace the "put-your-api-key-here" with the api key from your OpenWeatherMap account

Install go

$ brew install go

Prepare ~/.bash_profile or terminal session for Go development

export GOPATH=$HOME/go
export GOROOT=/usr/local/opt/go/libexec
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin

Install this package

$ go get github.com/rbbll/gin-microservice

Install gom

$ go get github.com/mattn/gom

Download and install all dependencies/versions from Gomfile

$ cd $GOPATH/src/github.com/rbbll/gin-microservice
$ gom install
$ VIPER_CONFIG=../config gom test ./app

Update dependencies (as needed)

$ rm -rf _vendor/
$ rm Gomfile.lock
$ gom lock
$ gom install

Run tests

$ VIPER_CONFIG=../config gom test ./app

Run tests (with logging)

$ VIPER_CONFIG=../config gom test -test.v ./app

See test coverage

$ cd $GOPATH/src/github.com/rbbll/gin-microservice
$ mkdir -p coverage
$ VIPER_CONFIG=../config gom test -coverprofile=coverage/coverage.out ./app
$ VIPER_CONFIG=../config gom tool cover -html=coverage/coverage.out -o coverage/coverage.html
$ open coverage/coverage.html

Start the application (development mode)

$ gom run main.go

Run commands from the project folder (Standalone binary)

$ gom build
$ VIPER_ENV=development VIPER_CONFIG=./config ./gin-microservice

About

Example microservice using the Go Gin framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages