最基础的gin框架的crud

package main

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

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

	r.GET("/hello", func(ctx *gin.Context) {
		ctx.JSON(http.StatusOK, gin.H{
			"msg": "hello world",
		})
	})

	r.POST("/user/list", func(ctx *gin.Context) {
		ctx.JSON(http.StatusOK, gin.H{
			"msg": "post user list",
		})
	})

	r.PUT("/user/add", func(ctx *gin.Context) {
		ctx.JSON(http.StatusOK, gin.H{
			"msg": "put user add",
		})
	})

	r.DELETE("/user/delete", func(ctx *gin.Context) {
		ctx.JSON(http.StatusOK, gin.H{
			"msg": "delete user delete",
		})
	})

	r.Run(":8080")
}

posted @ 2025-07-17 12:03  Charlie-Pang  阅读(8)  评论(0)    收藏  举报