memcached

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Memcache session support for Gorilla Web Toolkit, without Google App Engine dependency. https://github.com/bradleypeabody/gorilla-sessions-memcache/blob/master/LICENSE

Memcache session support for Gorilla Web Toolkit, https://github.com/bradleypeabody/gorilla-sessions-memcache/blob/master/LICENSE

Memcache session support for Gorilla Web Toolkit, https://github.com/bradleypeabody/gorilla-sessions-memcache/blob/master/LICENSE

Index

Constants

View Source
const (
	StoreMethodSecureCookie = StoreMethod("securecookie") // security
	StoreMethodGob          = StoreMethod("gob")          // speed
	StoreMethodJson         = StoreMethod("json")         // simplicity; warning: only string keys allowed and rest of data must be JSON.Marshal compatible
)

take your pick on how to store the values in memcache

Variables

View Source
var (
	// ErrHeaderFieldNameEmpty is returned, if the HeaderFieldName, which should be used to store session information, is empty.
	ErrHeaderFieldNameEmpty = errors.New("header fieldname empty")

	// ErrValueNotFound is returned, if no value was found for a given sessionName.
	ErrValueNotFound = errors.New("value not found")
)

Functions

This section is empty.

Types

type CookieStorer added in v0.1.1

type CookieStorer struct{}

CookieStorer is a ValueStorer, which stores values inside an http.Cookie

func (*CookieStorer) GetValueForSessionName added in v0.1.1

func (s *CookieStorer) GetValueForSessionName(r *http.Request, name string) (string, error)

GetValueForSessionName gets a value string from an http.Cookie, which should be present in the http.Request.

func (*CookieStorer) SetValueForSessionName added in v0.1.1

func (s *CookieStorer) SetValueForSessionName(w http.ResponseWriter, name, value string, options *sessions.Options) error

SetValueForSessionName sets a value string by creating a new http.Cookie and setting a `Set-Cookie` header

type GoMemcacher added in v0.1.1

type GoMemcacher struct {
	// contains filtered or unexported fields
}

GoMemcacher is a wrapper to the gomemcache client that implements the Memcacher interface

func NewGoMemcacher added in v0.1.1

func NewGoMemcacher(c *memcache.Client) *GoMemcacher

NewGoMemcacher returns a wrapped gomemcache client that implements the Memcacher interface

func (*GoMemcacher) Get added in v0.1.1

func (gm *GoMemcacher) Get(key string) (val string, flags uint32, cas uint64, err error)

func (*GoMemcacher) Set added in v0.1.1

func (gm *GoMemcacher) Set(key, val string, flags, exp uint32, ocas uint64) (cas uint64, err error)

type HeaderStorer added in v0.1.1

type HeaderStorer struct {
	HeaderFieldName string
}

HeaderStorer is a ValueStorer, which stores values inside an http Header. The key of the header contains can be configured using the `HeaderFieldName` variable. The header value is a Base64 encoded JSON map, whereas the keys of the map are the sessionName.

func (*HeaderStorer) GetValueForSessionName added in v0.1.1

func (s *HeaderStorer) GetValueForSessionName(r *http.Request, name string) (string, error)

GetValueForSessionName gets a value string from an http.Header.

func (*HeaderStorer) SetValueForSessionName added in v0.1.1

func (s *HeaderStorer) SetValueForSessionName(w http.ResponseWriter, name, value string, options *sessions.Options) error

SetValueForSessionName sets a value string by creating a new http.Header using the header key given by the headerStorer.HeaderKey function.

type MemcacheStore added in v0.1.1

type MemcacheStore struct {
	Codecs      []securecookie.Codec
	Options     *sessions.Options // default configuration
	Client      Memcacher
	KeyPrefix   string
	Logging     int // set to > 0 to enable logging (using log.Printf)
	StoreMethod StoreMethod
	ValueStorer ValueStorer
}

MemcacheStore stores sessions in memcache

func NewMemcacheStoreInt added in v0.1.1

func NewMemcacheStoreInt(client *memcache.Client, keyPrefix string, keyPairs ...[]byte) *MemcacheStore

NewMemcacheStore returns a new MemcacheStore for the gomemcache client (github.com/bradfitz/gomemcache/memcache). You also need to provider an optional prefix for the keys we store.

func NewMemcacheStoreWithValueStorer added in v0.1.1

func NewMemcacheStoreWithValueStorer(client *memcache.Client, valueStorer ValueStorer, keyPrefix string, keyPairs ...[]byte) *MemcacheStore

NewMemcacheStoreWithValueStorer returns a new MemcacheStore backed by a ValueStorer. You need to provide the gomemcache client (github.com/bradfitz/gomemcache/memcache) and an optional prefix for the keys we store. A ValueStorer is used to store an encrypted sessionID. The encrypted sessionID is used to access memcache and get the session values.

func NewMemcacherStore added in v0.1.1

func NewMemcacherStore(client Memcacher, keyPrefix string, keyPairs ...[]byte) *MemcacheStore

NewMemcacherStore returns a new MemcacheStore. You need to provide the memcache client that implements the Memcacher interface and an optional prefix for the keys we store

func NewMemcacherStoreWithValueStorer added in v0.1.1

func NewMemcacherStoreWithValueStorer(client Memcacher, valueStorer ValueStorer, keyPrefix string, keyPairs ...[]byte) *MemcacheStore

NewMemcacheStoreWithValueStorer returns a new MemcacheStore backed by a ValueStorer. You need to provide the memcache client that implements the Memcacher interface and an optional prefix for the keys we store. A ValueStorer is used to store an encrypted sessionID. The encrypted sessionID is used to access memcache and get the session values.

func (*MemcacheStore) Get added in v0.1.1

func (s *MemcacheStore) Get(r *http.Request, name string) (*sessions.Session, error)

Get returns a session for the given name after adding it to the registry.

See CookieStore.Get().

func (*MemcacheStore) MaxLength added in v0.1.1

func (s *MemcacheStore) MaxLength(l int)

MaxLength restricts the maximum length of new sessions to l. If l is 0 there is no limit to the size of a session, use with caution. The default for a new MemcacheStore is 4096.

func (*MemcacheStore) New added in v0.1.1

func (s *MemcacheStore) New(r *http.Request, name string) (*sessions.Session, error)

New returns a session for the given name without adding it to the registry.

See CookieStore.New().

func (*MemcacheStore) Save added in v0.1.1

Save adds a single session to the response.

type Memcacher added in v0.1.1

type Memcacher interface {
	Get(key string) (val string, flags uint32, cas uint64, err error)
	Set(key, val string, flags, exp uint32, ocas uint64) (cas uint64, err error)
}

Memcacher is the interface gsm uses to interact with the memcache client

type Store

type Store interface {
	sessions.Store
}

func NewMemcacheStore

func NewMemcacheStore(
	client gsm.Memcacher, keyPrefix string, keyPairs ...[]byte,
) Store

client: memcache client which implements the gsm.Memcacher interface keyPrefix: prefix for the keys we store.

func NewStore

func NewStore(
	client *memcache.Client, keyPrefix string, keyPairs ...[]byte,
) Store

client: memcache client (github.com/bradfitz/gomemcache/memcache) keyPrefix: prefix for the keys we store.

type StoreMethod added in v0.1.1

type StoreMethod string

type ValueStorer added in v0.1.1

type ValueStorer interface {
	// GetValueForSessionName gets a value string using it's underlying ValueStorer implementation.
	GetValueForSessionName(r *http.Request, name string) (string, error)

	// SetValueForSessionName sets a value string using it's underlying ValueStorer implementation.
	SetValueForSessionName(w http.ResponseWriter, name, value string, options *sessions.Options) error
}

ValueStorer stores a value for a given name inside a http.Request. The value is typically the encrypted sessionID, which can then be fetched by a Gorialla sessions.Store implementation.

Jump to

Keyboard shortcuts

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