package main
import (
"fmt"
"github.com/gin-gonic/gin"
"net/http"
)
func main() {
router := gin.Default()
count := 0
router.GET("/", func(context *gin.Context) {
if _, err := context.Cookie("cookie"); err != nil {
fmt.Println(err, "重置cookie")
context.SetCookie("cookie", "ok", 5, "/", "localhost", false, false)
count = 1
} else {
count++
}
context.JSON(http.StatusOK, gin.H{
"访问次数:": count,
})
})
router.Run(":7777")
}
测试完,留下你的答案