Skip to content

tomocy/sensei

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sensei

CircleCI License: MIT

utilities for gorilla/sessions

Installtion

go get github.com/tomocy/sensei

Useage

Create a Sensei instance with sessions.Store and session key

var manager = sensei.New(store, sessionKey)

var store = sessions.NewCookieStore(
    securecookie.GenerateRandomKey(64),
    securecookie.GenerateRandomKey(32),
)

const sessionKey = "BananaIsIncludedIntoSnacks"
func KeepAuthenticUserID(w http.ResponseWriter, r *http.Request, id string) error {
    return manager.Set(w, r, authenticUserID, id)
}

func FindAuthenticUserID(r *http.Request) (string, error) {
    if id, ok := manager.Get(r, authenticUserID); ok && id != "" {
        return id, nil
    }

    return "", errors.New("no authentic user id")
}

const (
    authentiUserID = "authentic_user_id"
)

Author

tomocy

Releases

No releases published

Packages

No packages published

Languages