Set and get a cookie

  1. import (
  2. "fmt"
  3. "github.com/gin-gonic/gin"
  4. )
  5. func main() {
  6. router := gin.Default()
  7. router.GET("/cookie", func(c *gin.Context) {
  8. cookie, err := c.Cookie("gin_cookie")
  9. if err != nil {
  10. cookie = "NotSet"
  11. c.SetCookie("gin_cookie", "test", 3600, "/", "localhost", false, true)
  12. }
  13. fmt.Printf("Cookie value: %s \n", cookie)
  14. })
  15. router.Run()
  16. }

Last modified March 7, 2020 : add blog dir (#115) (f46734b)