
Gin is a web framework written in Go and has the advantage of high performance.
1. Installation
Use go to download the gin library, command line input: go get github.com/gin-gonic/gin, generally use the required dependencies:
import "github.com/gin-gonic/gin" import "net/http"
Two: Basic application
1.Query method in gin.Context: get URL parameter
package main
import (
"github.com/gin-gonic/gin"
"net/http"
)
func getQuery(context *gin.Context){
userid := context.Query("userid")
username := context.Query("username")
context.String(http.StatusOK,userid+" "+username)
}
func main(){
// 注册一个默认路由器
router := gin.Default()
//注册GET处理
router.GET("/user", getQuery)
//默认8080端口
router.Run(":8088")
}Browser output:
5 xiaoming
2.gin. Param method in Context: RESRful style URL parameter passing
package main
import (
"github.com/gin-gonic/gin"
"net/http"
)
func getParam(context *gin.Context){
userid := context.Param("userid")
username := context.Param("username")
context.String(http.StatusOK,userid+" "+username)
}
func main(){
// 注册一个默认路由器
router := gin.Default()
//注册GET处理
//router.GET("/user", getQuery)
router.GET("/user/:userid/:username",getParam)
//默认8080端口
router.Run(":8088")
}Supplement: /:varname must match the corresponding one, /*varname must match all the following ones, and you cannot use more than one at the same time, otherwise a compilation error will be reported
Page output:
5 xiaoming
The above is the detailed content of What does gin mean?. For more information, please follow other related articles on the PHP Chinese website!
Yiou Exchange app download
How to solve the problem when the computer CPU temperature is too high
Usage of distinct in SQL
linux scheduled shutdown command
What's wrong with the air switch tripping?
what does focus mean
Introduction to the role of cloud servers
What are the java flow control statements?