项目作者: tomocy

项目描述 :
utilities for gorilla/sessions
高级语言: Go
项目地址: git://github.com/tomocy/sensei.git
创建时间: 2019-05-02T12:59:02Z
项目社区:https://github.com/tomocy/sensei

开源协议:MIT License

下载


Sensei

CircleCI
License: MIT

utilities for gorilla/sessions

Installtion

  1. go get github.com/tomocy/sensei

Useage

Create a Sensei instance with sessions.Store and session key

  1. var manager = sensei.New(store, sessionKey)
  2. var store = sessions.NewCookieStore(
  3. securecookie.GenerateRandomKey(64),
  4. securecookie.GenerateRandomKey(32),
  5. )
  6. const sessionKey = "BananaIsIncludedIntoSnacks"
  1. func KeepAuthenticUserID(w http.ResponseWriter, r *http.Request, id string) error {
  2. return manager.Set(w, r, authenticUserID, id)
  3. }
  4. func FindAuthenticUserID(r *http.Request) (string, error) {
  5. if id, ok := manager.Get(r, authenticUserID); ok && id != "" {
  6. return id, nil
  7. }
  8. return "", errors.New("no authentic user id")
  9. }
  10. const (
  11. authentiUserID = "authentic_user_id"
  12. )

Author

tomocy