Documentation ¶
Overview ¶
Package redis contains middleware that depends on github.com/garyburd/redigo/redis
Index ¶
- Constants
- func BuildRedis(redisAddr string) func(c *web.C, h http.Handler) http.Handler
- func BuildThrottleMiddleWare(interval int, keyfunc Keyfunc) func(c *web.C, h http.Handler) http.Handler
- func NewSessionHolder() base.SessionHolder
- type Keyfunc
- type SessionHolder
- func (sh *SessionHolder) Destroy(c web.C, session *base.Session) error
- func (sh *SessionHolder) Get(c web.C, r *http.Request) (*base.Session, error)
- func (sh *SessionHolder) RegenerateId(c web.C, session *base.Session) (string, error)
- func (sh *SessionHolder) ResetTTL(c web.C, session *base.Session) error
- func (sh *SessionHolder) Save(c web.C, session *base.Session) error
Constants ¶
View Source
const (
DEFAULT_SESSION_TIMEOUT = 30 * 24 * 60 * 60
)
Variables ¶
This section is empty.
Functions ¶
func BuildRedis ¶
A middleware that ensures a redis connection is present in c.Env["redis"]. The connection is built from a redigo Pool.
func BuildThrottleMiddleWare ¶
func BuildThrottleMiddleWare(interval int, keyfunc Keyfunc) func(c *web.C, h http.Handler) http.Handler
Throttling middleware using redis.
Parameters
interval - throttling interval in seconds keyfunc - function that looks at the current request and returns an appropriate throttle key and limit
Assumes redis connection is in c.Env["redis"] - see BuildRedis()
Example
m := web.New() m.Use(middleware.EnvInit) m.Use(redis.BuildRedis(config.RedisAddr)) m.Use(IdentifyServiceMiddleware) m.Use(redis.BuildThrottleMiddleWare(3600, func(c *web.C, r *http.Request) (string, int) { service_id := c.Env["service_id"].(int) return fmt.Sprintf("api:throttle:%d", service_id), 1000 }))
func NewSessionHolder ¶
func NewSessionHolder() base.SessionHolder
NewSessionHolder creates a new redis-backed gob-encoded session holder
Types ¶
type SessionHolder ¶
type SessionHolder struct {
base.BaseSessionHolder
}
SessionHolder is a redis-backed session store that gob-encodes sessions.
It requires a redigo redis connection set up in c.Env["redis"]. You can use BuildRedis() to create middleware that does this
func (*SessionHolder) RegenerateId ¶
Click to show internal directories.
Click to hide internal directories.