How to install golang gin

(*-*)浩
Release: 2019-12-13 10:53:05
Original
2586 people have browsed it

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
Copy after login

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
}
Copy after login

Execute test.go

go run test.go
Copy after login

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

curl 127.0.0.1:8080/ping
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template