# README
RESTful API with Go and Gin
Example of RESTful API written in Go and Gin framework.
This example project simply followed the official tutorial Tutorial: Developing a RESTful API with Go and Gin.
It may be slightly different from the original (more comments etc.).
How to get and run this example
$ git clone https://github.com/rideee/restful-api-with-go-and-gin $ cd restful-api-with-go-and-gin $ go get -u . $ go run .
Now you are ready to do some HTTP requests, you can use tools like
- Postman
- Insomnia
- curl - like in official tutorial
- REST Client - Visual Studio Code Extension
REST_Requests.http file
This file is used by REST Client (Visual Studio Code extension).
If you are using Visual Studio Code, you can install extension called REST Client which give you possibility to make HTTP requests from your editor.
Some examples requests are in REST_Requests.http file.
Troubleshooting
go: modules disabled by GO111MODULE=off (...)
$ go mod tidy go: modules disabled by GO111MODULE=off; see 'go help modules'
It means that your GO111MODULE environment variable is set to off.
You can check this using:
$ go env GO111MODULE="off" GOARCH="amd64" GOBIN="" ...
What is GO111MODULE?
From Go version 1.11, the way to deal with modules was revamped.
Beforehand, it was required that you place all your Go code under a $GOPATH. Which many Go developers didn’t much like, as it seemed chaotic at best.
Also, having a package management/module management solution is so much more productive, and manageable.
$ go help modules Modules are how Go manages dependencies. A module is a collection of packages that are released, versioned, and distributed together. Modules may be downloaded directly from version control repositories or from module proxy servers. For a series of tutorials on modules, see https://golang.org/doc/tutorial/create-module. For a detailed reference on modules, see https://golang.org/ref/mod. By default, the go command may download modules from https://proxy.golang.org. It may authenticate modules using the checksum database at https://sum.golang.org. Both services are operated by the Go team at Google. The privacy policies for these services are available at https://proxy.golang.org/privacy and https://sum.golang.org/privacy, respectively. The go command's download behavior may be configured using GOPROXY, GOSUMDB, GOPRIVATE, and other environment variables. See 'go help environment' and https://golang.org/ref/mod#private-module-privacy for more information.
- Go to -> Official - Series of tutorials on modules
- Go to -> Official - Detailed reference on modules
- Go to -> Official - Private Module Privacy
Solution
The easiest way to fix the problem is to set GO111MODULE environment variable to auto, using go env command (like below), then verify also by using go env:
$ go env -w GO111MODULE=auto $ go env GO111MODULE="auto" GOARCH="amd64" GOBIN="" ...