64 lines
1.0 KiB
Go
64 lines
1.0 KiB
Go
package response
|
|
|
|
import (
|
|
"github.com/gorilla/sessions"
|
|
)
|
|
|
|
type Session struct {
|
|
inner *sessions.Session
|
|
written bool
|
|
}
|
|
|
|
const flashKey = "_flash"
|
|
|
|
func (s *Session) FlashGet() any {
|
|
val, ok := s.inner.Values[flashKey]
|
|
if !ok {
|
|
return nil
|
|
}
|
|
delete(s.inner.Values, flashKey)
|
|
s.written = true
|
|
return val
|
|
}
|
|
|
|
func (s *Session) FlashPeek() any {
|
|
val, ok := s.inner.Values[flashKey]
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return val
|
|
}
|
|
|
|
func (s *Session) FlashSet(value any) {
|
|
s.inner.Values[flashKey] = value
|
|
s.written = true
|
|
}
|
|
|
|
func (s *Session) SetID(value string) {
|
|
s.inner.ID = value
|
|
s.written = true
|
|
}
|
|
|
|
func (s *Session) SetValue(key any, value any) {
|
|
s.inner.Values[key] = value
|
|
s.written = true
|
|
}
|
|
|
|
func (s *Session) RemoveValue(key any) {
|
|
delete(s.inner.Values, key)
|
|
s.written = true
|
|
}
|
|
|
|
func (s *Session) GetValue(key any) any {
|
|
return s.inner.Values[key]
|
|
}
|
|
|
|
func (s *Session) ClearValues() {
|
|
s.inner.Values = make(map[any]any)
|
|
s.written = true
|
|
}
|
|
|
|
func (s *Session) Options() *sessions.Options {
|
|
return s.inner.Options
|
|
}
|