api的url设计规则
router := gin.Default()
router.GET("/topic/:topic_id", func(context *gin.Context) {
context.String(http.StatusOK,"获取帖子Id为%s",context.Param("topic_id"))
})
router.Run()
router := gin.Default()
router.GET("/topic/:topic_id", func(context *gin.Context) {
context.String(http.StatusOK,"获取帖子Id为%s",context.Param("topic_id"))
})
router.Run()
package main
import (
"github.com/gin-gonic/gin"
)
type Topic struct {
TopicID int
}
func main() {
router := gin.Default()
router.GET("/topic/:topic_id", func(c *gin.Context) {
if c.Query("username") == "" {
c.String(200,"获取帖子列表")
}else{
c.String(200,"获取用户名=%s的帖子列表",c.Query("username"))
}
})
router.GET("/v1/topics/:topic_id", func(c *gin.Context) {
c.String(200,"获取topic=%s的帖子列表",c.Param("topic_id"))
})
router.Run()
}