user

package
v1.8.3 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package user implements a basic user management system.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserDuplicate = errors.New("duplicate user")
	ErrUserNotFound  = errors.New("user not found")
)

Errors.

Functions

This section is empty.

Types

type FirebaseManager

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

FirebaseManager is responsible for all user related operations

func NewFirebaseManager

func NewFirebaseManager(client *firestore.Client,
	collectionName string) FirebaseManager

NewFirebaseManager creates a new UserManager with the given firestore client and collection name.

func (FirebaseManager) Add

func (m FirebaseManager) Add(ctx context.Context,
	usr User) (<-chan *User, <-chan error)

Add adds a user to the database of users.

Please note that Add will return ErrUserDuplicate if the user already exists in the datastore.

func (FirebaseManager) Find

func (m FirebaseManager) Find(ctx context.Context,
	query datastore.Query) (<-chan (<-chan *User), <-chan error)

Find finds the user based on the given query criterion.

func (FirebaseManager) Update

func (m FirebaseManager) Update(ctx context.Context,
	user User) (<-chan *User, <-chan error)

Update updates the given user record.

Update will return ErrUserNotFound if the user cannot be found in the underlying datastore

type Manager

type Manager interface {
	// Add adds a user to the database of users.
	//
	// Add will return ErrUserDuplicate if the user already exists  in the
	// datastore.
	Add(ctx context.Context, user User) (<-chan *User, <-chan error)

	// Find finds the user based on the given query criteron
	Find(ctx context.Context,
		query datastore.Query) (<-chan (<-chan *User), <-chan error)

	// Update updates the given user record.
	//
	// Update will return ErrUserNotFound if the user cannot be found in the
	// underlying datastore
	Update(ctx context.Context, user User) (<-chan *User, <-chan error)
}

Manager is responsible for all user related operations.

Depending on how users are stored and queried, there could be multiple implementations of the Manager interface.

type User

type User struct {
	Username  string `json:"username"`
	Password  string `json:"password"`
	Suspended bool   `json:"suspended"`
}

User represents a user to be stored in the datastore.

Jump to

Keyboard shortcuts

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