go language gin framework use

go language gin framework use

install gin

  • Download the gin framework

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

    Error:

    go get github.com/gin-gonic/gin: module github.com/gin-gonic/gin: Get "https://proxy.golang.org/github.com/gin-gonic/gin/@v/list": dial tcp 172.217.160.113:443: connectex: A connection attempt failed because the connected party di d not properly respond a
    

    The reason for the error is that a proxy server needs to be configured

    solve:

    go env -w GO111MODULE=on
    go env -w GOPROXY=https://goproxy.io,direct
    
  • import "github.com/gin-gonic/gin"
    
    package main
    
    import "github.com/gin-gonic/gin"
    
    func main() {
          
          
    	r := gin.Default()
    	r.GET("/", func(c *gin.Context) {
          
          
    		c.JSON(200, gin.H{
          
          
    			"message": "hello go !",
    		})
    	})
    	// r.Run() // 默认为localhost:8080
    	r.Run(":8089") // 修改为8089
    }
    

test

Visit http://localhost:8089/ and the result is as follows

insert image description here

source of learning

official address

Guess you like

Origin blog.csdn.net/succeedcow/article/details/116656230