Quickstart
- Go 1.13 or above
To install Gin package, you need to install Go and set your Go workspace first.
- Download and install it:
- Import it in your code:
- (Optional) Import
net/http
. This is required for example if using constants such ashttp.StatusOK
.
import "net/http"
- Copy a starting template inside your project
$ curl https://raw.githubusercontent.com/gin-gonic/examples/master/basic/main.go > main.go
- Run your project
$ go run main.go
First, create a file called example.go
:
package main
import "github.com/gin-gonic/gin"
func main() {
r.GET("/ping", func(c *gin.Context) {
"message": "pong",
})
})
r.Run() // listen and serve on 0.0.0.0:8080
}
And, You can run the code via go run example.go
:
# run example.go and visit 0.0.0.0:8080/ping on browser