package main

import (
	"fmt"

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

// 中间件函数
func loggingMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		fmt.Println("loggingMiddleware start")
		c.Next()
		fmt.Println("loggingMiddleware end")
	}
}

func main() {
	r := gin.Default()
	// 将中间件函数应用到需要共享处理逻辑的路由上
	r.Use(loggingMiddleware())
	r.GET("/", func(c *gin.Context) {
		fmt.Println("这里是c.Next()")
	})

	r.Run(":8080")
}


//输出是
loggingMiddleware start
这里是c.Next()
loggingMiddleware end