session

package
v0.0.0-...-ed9fe1d Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2018 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package session provides github.com/speedland/go/web/middleware/session.SessionStore implementation for GAE environment

Index

Constants

View Source
const SessionKindLoggerKey = "ent.session"

SessionKindLoggerKey is a logger key name for the ent

View Source
const SessionQueryLoggerKey = "ent.query.session"

SessionQueryLoggerKey is a logger key name for the ent

Variables

View Source
var DefaultSessionKind = &SessionKind{}

DefaultSessionKind is a default value of *SessionKind

Functions

This section is empty.

Types

type GAESessionStore

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

GAESessionStore implements SessionStore on GAE memcache and datastore

func NewGAESessionStore

func NewGAESessionStore(namespace string) *GAESessionStore

NewGAESessionStore returns a new *SessionStore

func (*GAESessionStore) Del

func (s *GAESessionStore) Del(ctx context.Context, session *session.Session) error

Del implements SessionStore#Del

func (*GAESessionStore) Get

Get implements SessionStore#Get

func (*GAESessionStore) Set

func (s *GAESessionStore) Set(ctx context.Context, session *session.Session) error

Set implements SessionStore#Set

func (*GAESessionStore) String

func (s *GAESessionStore) String() string

type Session

type Session struct {
	ID         string    `json:"id" ent:"id"`
	CSRFSecret string    `json:"csrf_secret" datastore:",noindex"`
	Timestamp  time.Time `json:"key" ent:"timestamp" datastore:",noindex"`
	Data       []byte    `json:"data" datastore:",noindex"`
}

Session is a wrapped struct for github.com/speedland/go/web/middleware/sesison.Session

func NewSession

func NewSession() *Session

NewSession returns a new *Session with default field values.

func (*Session) NewKey

func (s *Session) NewKey(ctx context.Context) *datastore.Key

func (*Session) UpdateByForm

func (s *Session) UpdateByForm(form *keyvalue.GetProxy)

UpdateByForm updates the fields by form values. All values should be validated before calling this function.

type SessionKind

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

func (*SessionKind) Delete

func (k *SessionKind) Delete(ctx context.Context, key interface{}) (*datastore.Key, error)

Delete deletes the entity from datastore

func (*SessionKind) DeleteMatched

func (k *SessionKind) DeleteMatched(ctx context.Context, q *SessionQuery) (int, error)

DeleteMatched deletes the all ents that match with the query. This func modify Limit/StartKey condition in the query so that you should restore it if you want to reuse the query.

func (*SessionKind) DeleteMulti

func (k *SessionKind) DeleteMulti(ctx context.Context, keys interface{}) ([]*datastore.Key, error)

DeleteMulti do Delete with multiple keys

func (*SessionKind) EnforceNamespace

func (k *SessionKind) EnforceNamespace(ns string, b bool) *SessionKind

EnforceNamespace enforces namespace for Get/Put/Delete or not.

func (*SessionKind) Get

func (k *SessionKind) Get(ctx context.Context, key interface{}) (*datastore.Key, *Session, error)

Get gets the kind entity from datastore

func (*SessionKind) GetMulti

func (k *SessionKind) GetMulti(ctx context.Context, keys interface{}) ([]*datastore.Key, []*Session, error)

GetMulti do Get with multiple keys. keys must be []string, []*datastore.Key, or []interface{}

func (*SessionKind) MustDelete

func (k *SessionKind) MustDelete(ctx context.Context, key interface{}) *datastore.Key

MustDelete is like Delete but panic if an error occurs

func (*SessionKind) MustDeleteMulti

func (k *SessionKind) MustDeleteMulti(ctx context.Context, keys interface{}) []*datastore.Key

MustDeleteMulti is like DeleteMulti but panic if an error occurs

func (*SessionKind) MustGet

func (k *SessionKind) MustGet(ctx context.Context, key interface{}) *Session

MustGet is like Get but returns only values and panic if error happens.

func (*SessionKind) MustGetMulti

func (k *SessionKind) MustGetMulti(ctx context.Context, keys interface{}) []*Session

MustGetMulti is like GetMulti but returns only values and panic if error happens.

func (*SessionKind) MustPut

func (k *SessionKind) MustPut(ctx context.Context, ent *Session) *datastore.Key

MustPut is like Put and panic if an error occurrs.

func (*SessionKind) MustPutMulti

func (k *SessionKind) MustPutMulti(ctx context.Context, ents []*Session) []*datastore.Key

MustPutMulti is like PutMulti but panic if an error occurs

func (*SessionKind) MustReplace

func (k *SessionKind) MustReplace(ctx context.Context, ent *Session, replacer SessionKindReplacer) (*datastore.Key, *Session)

func (*SessionKind) MustReplaceMulti

func (k *SessionKind) MustReplaceMulti(ctx context.Context, ents []*Session, replacer SessionKindReplacer) ([]*datastore.Key, []*Session)

func (*SessionKind) Put

func (k *SessionKind) Put(ctx context.Context, ent *Session) (*datastore.Key, error)

Put puts the entity to datastore.

func (*SessionKind) PutMulti

func (k *SessionKind) PutMulti(ctx context.Context, ents []*Session) ([]*datastore.Key, error)

PutMulti do Put with multiple keys

func (*SessionKind) Replace

func (k *SessionKind) Replace(ctx context.Context, ent *Session, replacer SessionKindReplacer) (*datastore.Key, *Session, error)

func (*SessionKind) ReplaceMulti

func (k *SessionKind) ReplaceMulti(ctx context.Context, ents []*Session, replacer SessionKindReplacer) ([]*datastore.Key, []*Session, error)

func (*SessionKind) UseDefaultIfNil

func (k *SessionKind) UseDefaultIfNil(b bool) *SessionKind

type SessionKindReplacer

type SessionKindReplacer interface {
	Replace(*Session, *Session) *Session
}

type SessionKindReplacerFunc

type SessionKindReplacerFunc func(*Session, *Session) *Session

func (SessionKindReplacerFunc) Replace

func (f SessionKindReplacerFunc) Replace(ent1 *Session, ent2 *Session) *Session

type SessionPagination

type SessionPagination struct {
	Start string           `json:"start"`
	End   string           `json:"end"`
	Count int              `json:"count,omitempty"`
	Data  []*Session       `json:"data"`
	Keys  []*datastore.Key `json:"-"`
}

type SessionQuery

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

SessionQuery helps to build and execute a query

func NewSessionQuery

func NewSessionQuery() *SessionQuery

func (*SessionQuery) Ancestor

func (q *SessionQuery) Ancestor(a lazy.Value) *SessionQuery

Ancestor sets the ancestor filter

func (*SessionQuery) Asc

func (q *SessionQuery) Asc(name string) *SessionQuery

Asc specifies ascending order on the given filed.

func (*SessionQuery) Count

func (q *SessionQuery) Count(ctx context.Context) (int, error)

Count returns the count of entities

func (*SessionQuery) Desc

func (q *SessionQuery) Desc(name string) *SessionQuery

Desc specifies descending order on the given filed.

func (*SessionQuery) End

func (q *SessionQuery) End(value lazy.Value) *SessionQuery

Limit specifies the numbe of limit returend by this query.

func (*SessionQuery) Eq

func (q *SessionQuery) Eq(name string, value lazy.Value) *SessionQuery

Eq sets the "=" filter on the name field.

func (*SessionQuery) Ge

func (q *SessionQuery) Ge(name string, value lazy.Value) *SessionQuery

Ge sets the ">=" filter on the "name" field.

func (*SessionQuery) GetAll

func (q *SessionQuery) GetAll(ctx context.Context) ([]*datastore.Key, []*Session, error)

GetAll returns all key and value of the query.

func (*SessionQuery) GetAllValues

func (q *SessionQuery) GetAllValues(ctx context.Context) ([]*Session, error)

GetAllValues is like GetAll but returns only values

func (*SessionQuery) Gt

func (q *SessionQuery) Gt(name string, value lazy.Value) *SessionQuery

Gt sets the ">" filter on the "name" field.

func (*SessionQuery) Le

func (q *SessionQuery) Le(name string, value lazy.Value) *SessionQuery

Le sets the "<=" filter on the "name" field.

func (*SessionQuery) Limit

func (q *SessionQuery) Limit(n lazy.Value) *SessionQuery

Limit specifies the numbe of limit returend by this query.

func (*SessionQuery) Lt

func (q *SessionQuery) Lt(name string, value lazy.Value) *SessionQuery

Lt sets the "<" filter on the "name" field.

func (*SessionQuery) MustCount

func (q *SessionQuery) MustCount(ctx context.Context) int

MustCount returns the count of entities

func (*SessionQuery) MustGetAll

func (q *SessionQuery) MustGetAll(ctx context.Context) ([]*datastore.Key, []*Session)

MustGetAll is like GetAll but panic if an error occurrs.

func (*SessionQuery) MustGetAllValues

func (q *SessionQuery) MustGetAllValues(ctx context.Context) []*Session

MustGetAllValues is like GetAllValues but panic if an error occurrs

func (*SessionQuery) MustRun

func (q *SessionQuery) MustRun(ctx context.Context) *SessionPagination

MustRun is like Run but panic if an error occurrs

func (*SessionQuery) Ne

func (q *SessionQuery) Ne(name string, value lazy.Value) *SessionQuery

Ne sets the "!=" filter on the "name" field.

func (*SessionQuery) Run

Run returns the a result as *SessionPagination object

func (*SessionQuery) Start

func (q *SessionQuery) Start(value lazy.Value) *SessionQuery

Limit specifies the numbe of limit returend by this query.

func (*SessionQuery) ViaKeys

func (q *SessionQuery) ViaKeys(k *SessionKind) *SessionQuery

ViaKeys optimize to execute keys-only query then call k.GetMulti() to fetch values. This would reduce the datastore query and maximize the memcache usage if the query called many times in a short time window.

Jump to

Keyboard shortcuts

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