Installation
To install Gin package, you need to install Go and set your Go workspace first.
- Download and install it:
$ go get -u github.com/gin-gonic/gin
- Import it in your code:
import "github.com/gin-gonic/gin"
- (Optional) Import
net/http
. This is required for example if using constants such ashttp.StatusOK
.
import "net/http"
Use a vendor tool like Govendor
go get
govendor
$ go get github.com/kardianos/govendor
- Create your project folder and
cd
inside
$ mkdir -p $GOPATH/src/github.com/myusername/project && cd "$_"
- Vendor init your project and add gin
$ govendor init
$ govendor fetch github.com/gin-gonic/gin@v1.2
- Copy a starting template inside your project
$ curl https://raw.githubusercontent.com/gin-gonic/gin/master/examples/basic/main.go > main.go
- Run your project
$ go run main.go