Documentation ¶
Overview ¶
Package user implements a user management system.
Index ¶
- Variables
- type FirestoreManager
- type Manager
- type User
- func (u *User) WithDisplayName(displayName string) *User
- func (u *User) WithEmail(email string) *User
- func (u *User) WithPassword(password string) *User
- func (u *User) WithPhoneNumber(phoneNumber string) *User
- func (u *User) WithPhotoURL(photoURL string) *User
- func (u *User) WithSuspended(suspended bool) *User
- func (u *User) WithUID(uid string) *User
- func (u *User) WithUsername(username string) *User
Constants ¶
This section is empty.
Variables ¶
var ( ErrUserDuplicate = errors.New("duplicate user") ErrUserNotFound = errors.New("user not found") )
Errors.
Functions ¶
This section is empty.
Types ¶
type FirestoreManager ¶
type FirestoreManager struct {
// contains filtered or unexported fields
}
FirestoreManager is an UserManager implementation that uses firebase firestore as the underlying user information storage engine.
func NewFirestoreManager ¶
func NewFirestoreManager(client *firestore.Client, collectionName string) *FirestoreManager
NewFirestoreManager creates a new FirestoreManager with the given firestore client and collection name.
func (*FirestoreManager) Add ¶
Add adds a user to the database of users.
Please note that a user is considered a duplicate if any of the following already exist on a different user: Email, PhoneNumber, and Username. The Add method will return ErrUserDuplicate in this case.
func (*FirestoreManager) Find ¶
func (m *FirestoreManager) Find(ctx context.Context, queries ...datastore.Query) (<-chan *User, <-chan error)
Find finds the user based on the given query criterion.
If multiple queries are sent, the queries are combined with OR condition. Please refer to https://pkg.go.dev/github.com/qqiao/webapp/v2/datastore/firestore#Or for limitations of OR queries.
type Manager ¶
type Manager interface { // Add adds a user to the database of users. // // Please note that a user is considered a duplicate if any of the // following already exist on a different user: Email, PhoneNumber, and // Username. The Add method will return ErrUserDuplicate in this case. Add(ctx context.Context, user *User) (<-chan *User, <-chan error) // Find finds the user based on the given query criterion. // // If multiple queries are sent, the queries are combined with OR // condition. Please refer to https://pkg.go.dev/github.com/qqiao/webapp/v2/firebase/firestore#Or // for limitations of OR queries. Find(ctx context.Context, queries ...datastore.Query) (<-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. This interface defines common operations for managing user records.
Depending on how users are stored and queried, there could be multiple implementations of the Manager interface.
type User ¶
type User struct { DisplayName string `json:"displayName,omitempty"` Email string `json:"email,omitempty"` Password string `json:"password,omitempty"` PhoneNumber string `json:"phoneNumber,omitempty"` PhotoURL string `json:"photoUrl,omitempty"` Suspended bool `json:"-"` UID string `json:"uid,omitempty" firestore:"-"` Username string `json:"username,omitempty"` }
User represents a user record stored in the underlying datastore.
func NewUser ¶
func NewUser() *User
NewUser returns a new User instance with all fields being blank.
func (*User) WithDisplayName ¶
WithDisplayName sets the DisplayName of the user.
func (*User) WithPassword ¶
WithPassword sets the Password of the user.
func (*User) WithPhoneNumber ¶
WithPhoneNumber sets the PhoneNumber of the user.
func (*User) WithPhotoURL ¶
WithPhotoURL sets the PhotoURL of the user.
func (*User) WithSuspended ¶
WithSuspended sets the Suspended of the user.
func (*User) WithUsername ¶
WithUsername sets the Username of the user.