1234567891011121314151617181920212223242526272829303132 |
- package util
- import (
- "github.com/gin-gonic/gin"
- )
- type PosterCookie struct {
- Cookie map[string]string
- ctx *gin.Context
- }
- func NewPosterCookie(ctx *gin.Context) *PosterCookie {
- return &PosterCookie{ctx: ctx, Cookie: map[string]string{}}
- }
- func (cookie *PosterCookie) SetCookie(name, value string, expireAt int) {
- cookie.Cookie[name] = value
- for key, val := range cookie.Cookie {
- cookie.ctx.SetCookie(key, val, expireAt, "/", "", true, false)
- }
- }
- func (cookie *PosterCookie) Get(name string) *string {
- val, err := cookie.ctx.Cookie(name)
- if err != nil {
- return nil
- }
- return &val
- }
|