gin/api-param/main.go

26 lines
527 B
Go

package main
import (
"github.com/gin-gonic/gin"
"net/http"
)
func main() {
r := gin.Default()
//可以添加api参数
//访问的是 localhost:8000/user/{$name}
r.GET("/user/:name", func(c *gin.Context) {
name := c.Param("name")
c.String(http.StatusOK, name)
})
//访问的是 localhost:8000/user/{$name}/*
//返回结果{$name} is /*
r.GET("/user/:name/*ready", func(c *gin.Context) {
name := c.Param("name")
action := c.Param("ready")
c.String(http.StatusOK, name+" is "+action)
})
r.Run(":8000")
}