-
Notifications
You must be signed in to change notification settings - Fork 38
/
token.go
28 lines (21 loc) · 622 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
package mongostore
import (
"net/http"
"github.com/gorilla/sessions"
)
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))
}