datastore

package
v0.0.0-...-ca023d2 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Overview

Package datastore implements session storage over Cloud Datastore.

Index

Constants

View Source
const InactiveSessionExpiration time.Duration = 14 * 24 * time.Hour

InactiveSessionExpiration is used to derive ExpireAt field of the datastore entity.

It defines how long to keep inactive session in the datastore before they are cleaned up by a TTL policy.

Variables

This section is empty.

Functions

This section is empty.

Types

type SessionEntity

type SessionEntity struct {
	ID      string             `gae:"$id"`
	Session *sessionpb.Session `gae:",nocompress"`

	State       sessionpb.State
	Created     time.Time
	LastRefresh time.Time
	NextRefresh time.Time
	Closed      time.Time
	Sub         string
	Email       string

	// ExpireAt is used in a Cloud Datastore TTL policy.
	//
	// It is derived from LastRefresh (or the current time if LastRefresh is not
	// populated) based on InactiveSessionExpiration whenever the entity is
	// stored.
	ExpireAt time.Time `gae:",noindex"`
	// contains filtered or unexported fields
}

SessionEntity is what is actually stored in the datastore.

type Store

type Store struct {
	Namespace string // the datastore namespace to use or "" for default
}

Store uses Cloud Datastore for sessions.

func (*Store) FetchSession

func (s *Store) FetchSession(ctx context.Context, id session.ID) (*sessionpb.Session, error)

FetchSession fetches an existing session with the given ID.

Returns (nil, nil) if there's no such session. All errors are transient.

func (*Store) UpdateSession

func (s *Store) UpdateSession(ctx context.Context, id session.ID, cb func(*sessionpb.Session) error) error

UpdateSession transactionally updates or creates a session.

If fetches the session, calls the callback to mutate it, and stores the result. If it is a new session, the callback receives an empty proto.

The callback may be called multiple times in case the transaction is retried. Errors from callbacks are returned as is. All other errors are transient.

Jump to

Keyboard shortcuts

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