Home>Article>Backend Development> How to install golang gin

How to install golang gin

(*-*)浩
(*-*)浩 Original
2019-12-13 10:53:05 2507browse

How to install golang gin

Gin is a web framework written in go, which implements APIs similar to the Martini framework with better performance.

# Install gin

stepping down in the command line(Recommended learning:Go)

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

Check whether the gin code package exists in /usr/local/go/path

Test whether Gin is installed successfully

Write a test. go file

package main import "github.com/gin-gonic/gin" func main() { r := gin.Default() r.GET("/ping", func(c *gin.Context) { c.JSON(200, gin.H{ "message": "pong", }) }) r.Run() // listen and serve on 0.0.0.0:8080 }

Execute test.go

go run test.go

Access $HOST:8080/ping, if {"message":"pong"} is returned, it is correct

curl 127.0.0.1:8080/ping

At this point, our environment installation is basically completed:)

The above is the detailed content of How to install golang gin. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to use golang gf Next article:How to use golang gf