package main
import (
"github.com/gin-gonic/gin"
"io"
"net/http"
"os"
)
//中间件 日志记录 与 错误抑制
func main() {
//日志位置
f,_:= os.Create("E:/Go/awesomeProject/middleware_中间件/gin.log")
gin.DefaultWriter = io.MultiWriter(f)
gin.DefaultErrorWriter = io.MultiWriter(f) //错误信息
router := gin.New()
router.Use(gin.Logger(),gin.Recovery())
router.GET("/aaa", func(context *gin.Context) {
panic("132132132")
context.String(http.StatusOK, "哈哈哈")
})
router.Any("/bbb", func(context *gin.Context) {
context.String(http.StatusOK, "hello 哈哈哈")
})
router.Run()
}