session

package module
v0.0.0-...-c394b13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2016 License: Apache-2.0 Imports: 11 Imported by: 1

README

session

Middleware session provides session management for Martini.

Installation
go get github.com/codinl/session

License

This project is under Apache v2 License. See the LICENSE file for the full license text.

Documentation

Index

Constants

View Source
const (
	SESSION_USER               = "session_user"
	COOKIE_NAME                = "sessionid"
	MAX_AGE      time.Duration = 3600
)

Variables

View Source
var (
	RedirectUrl      string = "/account/login"
	AdminRedirectUrl string = "/admin/account/login"
	RedirectParam    string = "next"
)

Functions

func AdminRequired

func AdminRequired(user User, req *http.Request, resp http.ResponseWriter)

func Handler

func Handler(newUser func() User, options ...Option) martini.Handler

Handler is a middleware that maps a Session service into the Martini handler chain.

func LoginRequired

func LoginRequired(user User, req *http.Request, resp http.ResponseWriter)

Types

type Option

type Option struct {
	CookiePath string
	Domain     string
	CookieName string
	// MaxAge=0 means no 'Max-Age' attribute specified.
	// MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'.
	// MaxAge>0 means Max-Age attribute present and given in seconds.
	MaxAge   time.Duration
	Secure   bool
	HttpOnly bool
}

Option stores configuration for a session or session store.

Fields are a subset of http.Cookie fields.

type Session

type Session interface {
	Set(key string, value interface{})
	Get(key string) (value interface{}, found bool)
	Delete(key string)
	Authenticate(user User) error
	UnAuthenticate() error
}

func NewSession

func NewSession(req *http.Request, resp http.ResponseWriter, sid string) Session

type User

type User interface {
	Login() int
	Logout() int
	IsAdmin() bool
	IsAuthenticated() bool
	UniqueId() interface{}
	GetById(id interface{}) (User, int)
}

User

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL