forked from go-playground/mongostore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.go
33 lines (24 loc) · 804 Bytes
/
token.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package mongostore
import (
"net/http"
"github.com/gorilla/sessions"
)
// TokenGetSeter is the interface for setting and receiving the cookie token
type TokenGetSeter interface {
GetToken(r *http.Request, name string) (string, error)
SetToken(w http.ResponseWriter, name, value string, options *sessions.Options)
}
// CookieToken struct
type CookieToken struct{}
// GetToken returns a Cookie valie and eny errors
func (c *CookieToken) GetToken(r *http.Request, name string) (string, error) {
cookie, err := r.Cookie(name)
if err != nil {
return "", err
}
return cookie.Value, nil
}
// SetToken sets the sessions cookie
func (c *CookieToken) SetToken(w http.ResponseWriter, name, value string, options *sessions.Options) {
http.SetCookie(w, sessions.NewCookie(name, value, options))
}