cookie.go 807 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package cookie
  5. import (
  6. "net/http"
  7. "time"
  8. )
  9. // Cookie names.
  10. const (
  11. CookieSessionID = "sessionID"
  12. CookieUserSessionID = "userSessionID"
  13. )
  14. // New create a new cookie.
  15. func New(name, value string, isHTTPS bool) *http.Cookie {
  16. return &http.Cookie{
  17. Name: name,
  18. Value: value,
  19. Path: "/",
  20. Secure: isHTTPS,
  21. HttpOnly: true,
  22. }
  23. }
  24. // Expired returns an expired cookie.
  25. func Expired(name string, isHTTPS bool) *http.Cookie {
  26. return &http.Cookie{
  27. Name: name,
  28. Value: "",
  29. Path: "/",
  30. Secure: isHTTPS,
  31. HttpOnly: true,
  32. MaxAge: -1,
  33. Expires: time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC),
  34. }
  35. }