gae

package
v0.7.43 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gae provides a Google Cloud Datastore session store for scs (alexedwards/scs/v2). It stores session data in Datastore with automatic expiration cleanup.

Usage

client, _ := datastore.NewClient(ctx, projectID)
sessionStore := gae.NewGCDSessionStore(client, "", time.Hour) // cleanup every hour
session := scs.New()
session.Store = sessionStore

Datastore Kind

Sessions are stored with the kind "AuthSession" and the following properties:

  • Token: string (used as key name)
  • ExpiresAt: time.Time (indexed for cleanup queries)
  • Data: []byte (session data, noindex)

Namespacing

The store supports Datastore namespaces for multi-tenant applications:

sessionStore := gae.NewGCDSessionStore(client, "tenant-123", time.Hour)

Package gae provides a Google Cloud Datastore implementation of the UsersService. It is designed for deployment on Google Cloud Platform and supports multi-tenancy through Datastore namespaces.

Datastore Kind

Users are stored with the kind "User" and the following properties:

  • id: string (used as key name, not stored as property)
  • created_at, updated_at: timestamps
  • name, description, email, image_url: strings
  • tags: []string (noindex)
  • extras: Struct (noindex, for app-specific data)

Namespacing

The service supports Datastore namespaces for multi-tenant applications. Pass a namespace to NewUsersService to isolate data between tenants:

userService := gae.NewUsersService(client, "tenant-123")

Generated Code

This package uses protoc-gen-dal-datastore generated code:

  • UserDatastore: Datastore entity model
  • UserDatastoreToUser/UserToUserDatastore: conversion functions
  • UserDatastoreDAL: data access layer with CRUD operations

Usage

client, _ := datastore.NewClient(ctx, projectID)
userService := gae.NewUsersService(client, "")  // default namespace
resp, err := userService.CreateUser(ctx, &v1.CreateUserRequest{
    User: &v1.User{Name: "John Doe", Email: "john@example.com"},
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthSession

type AuthSession struct {
	Token     string    `datastore:"-"` // Key name, not stored as property
	ExpiresAt time.Time `datastore:"expiresAt"`
	Data      []byte    `datastore:"data,noindex"`
}

AuthSession represents a session entity in Datastore.

type GCDSessionStore

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

GCDSessionStore implements the scs.Store interface using Google Cloud Datastore.

func NewGCDSessionStore

func NewGCDSessionStore(client *datastore.Client, namespace string, cleanupInterval time.Duration) *GCDSessionStore

NewGCDSessionStore creates a new Datastore-backed session store. The cleanupInterval parameter controls how frequently expired session data is removed. Setting it to 0 disables the background cleanup goroutine.

func (*GCDSessionStore) AllCtx

func (s *GCDSessionStore) AllCtx(ctx context.Context) (map[string][]byte, error)

AllCtx returns a map containing the token and data for all active (non-expired) sessions.

func (*GCDSessionStore) Commit

func (s *GCDSessionStore) Commit(token string, data []byte, expiry time.Time) error

func (*GCDSessionStore) CommitCtx

func (s *GCDSessionStore) CommitCtx(ctx context.Context, token string, data []byte, expiry time.Time) error

CommitCtx adds a session token and data to Datastore with the given expiry time. If the session token already exists, the data and expiry time are updated.

func (*GCDSessionStore) Delete

func (s *GCDSessionStore) Delete(token string) error

func (*GCDSessionStore) DeleteCtx

func (s *GCDSessionStore) DeleteCtx(ctx context.Context, token string) error

DeleteCtx removes a session token and corresponding data from Datastore.

func (*GCDSessionStore) Find

func (s *GCDSessionStore) Find(token string) ([]byte, bool, error)

func (*GCDSessionStore) FindCtx

func (s *GCDSessionStore) FindCtx(ctx context.Context, token string) ([]byte, bool, error)

FindCtx returns the data for a given session token. If the session token is not found or is expired, the returned exists flag will be false.

func (*GCDSessionStore) StopCleanup

func (s *GCDSessionStore) StopCleanup()

StopCleanup terminates the background cleanup goroutine.

type UsersService

type UsersService struct {
	services.BaseUsersService

	MaxPageSize int
	UserDAL     v1dal.UserDatastoreDAL
	// contains filtered or unexported fields
}

UsersService implements services.UsersService using Google Cloud Datastore. It embeds BaseUsersService to inherit caching and shared operations.

func NewUsersService

func NewUsersService(client *datastore.Client, namespace string) *UsersService

NewUsersService creates a new Datastore-backed UsersService. The namespace parameter supports multi-tenancy; pass empty string for default namespace.

func (*UsersService) CreateUser

CreateUser creates a new user profile.

func (*UsersService) DeleteFromStorage

func (s *UsersService) DeleteFromStorage(ctx context.Context, id string) error

DeleteFromStorage implements UserStorageProvider.

func (*UsersService) ListAllUsers

func (s *UsersService) ListAllUsers(ctx context.Context) ([]*v1.User, error)

ListAllUsers implements UserStorageProvider.

func (*UsersService) LoadUser

func (s *UsersService) LoadUser(ctx context.Context, id string) (*v1.User, error)

LoadUser implements UserStorageProvider.

func (*UsersService) NamespacedKey

func (s *UsersService) NamespacedKey(kind, name string) *datastore.Key

NamespacedKey creates a Datastore key with the configured namespace

func (*UsersService) SaveUser

func (s *UsersService) SaveUser(ctx context.Context, id string, user *v1.User) error

SaveUser implements UserStorageProvider.

func (*UsersService) UpdateUser

UpdateUser updates an existing user profile.

func (*UsersService) UserExists

func (s *UsersService) UserExists(ctx context.Context, id string) bool

UserExists implements UserStorageProvider.

Jump to

Keyboard shortcuts

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