1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00
cowyo/vendor/github.com/kidstuff/mongostore/token.go

28 lines
621 B
Go
Raw Permalink Normal View History

2017-10-03 21:43:55 +03:00
package mongostore
import (
"github.com/gorilla/sessions"
"net/http"
)
type TokenGetSeter interface {
GetToken(req *http.Request, name string) (string, error)
SetToken(rw http.ResponseWriter, name, value string, options *sessions.Options)
}
type CookieToken struct{}
func (c *CookieToken) GetToken(req *http.Request, name string) (string, error) {
cook, err := req.Cookie(name)
if err != nil {
return "", err
}
return cook.Value, nil
}
func (c *CookieToken) SetToken(rw http.ResponseWriter, name, value string,
options *sessions.Options) {
http.SetCookie(rw, sessions.NewCookie(name, value, options))
}