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

33 lines
581 B
Go
Raw Normal View History

/*
* @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()
}