Gin获取Path参数

时间:2021-08-30 11:00:42   收藏:0   阅读:10
package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

func getPath(ctx *gin.Context) {
	id := ctx.Param("id")
	ctx.JSON(http.StatusOK, gin.H{
		"id": id,
	})
}

func main() {
	router := gin.Default()

	router.GET("/user/:id", getPath)

	err := router.Run(":8080")
	if err != nil {
		fmt.Println(err)
		return
	}
}

原文:https://www.cnblogs.com/liy36/p/15201291.html

评论(0)
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!