Files
Go-StudyExample/example/gin/31-ReadCookie_test.go

33 lines
581 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* @Author : huangzj
* @Time : 2020/12/8 15:27
* @Description
*/
package gin
import (
"fmt"
"github.com/gin-gonic/gin"
"testing"
)
func TestReadCookie(t *testing.T) {
router := gin.Default()
router.GET("/cookie", func(c *gin.Context) {
//read note 这边需要web前端发送对应的cookie
cookie, err := c.Cookie("gin_cookie")
//read note 设置对应值的cookie
if err != nil {
cookie = "NotSet"
c.SetCookie("gin_cookie", "test", 3600, "/", "localhost", false, true)
}
fmt.Printf("Cookie value: %s \n", cookie)
})
_ = router.Run()
}