Documentation
¶
Overview ¶
Package user provides an example of a core business API. Right now these calls are just wrapping the data/data layer. But at some point you will want auditing or something that isn't specific to the data/store layer.
Index ¶
- Variables
- type Core
- func (c *Core) Authenticate(ctx context.Context, phone, password string) (User, error)
- func (c *Core) Create(ctx context.Context, core NewUser) (User, error)
- func (c *Core) QueryByID(ctx context.Context, id uuid.UUID) (User, error)
- func (c *Core) QueryByPhone(ctx context.Context, phone string) (User, error)
- func (c *Core) Update(ctx context.Context, o User, n UpdateUser) (User, error)
- type NewUser
- type Role
- type Status
- type Storer
- type UpdateUser
- type User
Constants ¶
This section is empty.
Variables ¶
var ( RoleAdmin = Role{"ADMIN"} RoleUser = Role{"USER"} )
Set of possible roles for a user.
var ( StatusCreated = Status{"CREATED"} StatusActive = Status{"ACTIVE"} StatusDeleted = Status{"DELETED"} )
Set of possible status for a user.
var ( ErrNotFound = errors.New("user not found") ErrUniquePhone = errors.New("phone is not unique") ErrAuthenticationFailure = errors.New("authentication failed") ErrInvalidUserStatus = errors.New("invalid user status") )
Set of error variables for CRUD operations.
Functions ¶
This section is empty.
Types ¶
type Core ¶
type Core struct {
// contains filtered or unexported fields
}
Core manages the set of APIs for user access.
func (*Core) Authenticate ¶
Authenticate finds a user by their phone and verifies their password. On success it returns a Claims User representing this user. The claims can be used to generate a token for future authentication.
func (*Core) QueryByPhone ¶
QueryByPhone finds the user by a specified user phone.
type NewUser ¶
type NewUser struct { FirstName string LastName string Phone string Password string Status Status Roles []Role }
NewUser contains information needed to create a new user.
type Role ¶
type Role struct {
// contains filtered or unexported fields
}
Role represents a role in the system.
func MustParseRole ¶
MustParseRole parses the string value and returns a role if one exists. If an error occurs the function panics.
func (*Role) MarshalText ¶
MarshalText implement the marshal interface for JSON conversions.
func (*Role) UnmarshalText ¶
UnmarshalText implement the unmarshal interface for JSON conversions.
type Status ¶
type Status struct {
// contains filtered or unexported fields
}
Status represents a user status in the system.
func MustParseStatus ¶
MustParseStatus parses the string value and returns a status if one exists. If an error occurs the function panics.
func ParseStatus ¶
ParseStatus parses the string value and returns a status if one exists.
func (*Status) MarshalText ¶
MarshalText implement the marshal interface for JSON conversions.
func (*Status) UnmarshalText ¶
UnmarshalText implement the unmarshal interface for JSON conversions.
type Storer ¶
type Storer interface { Create(ctx context.Context, core User) error Update(ctx context.Context, core User) error QueryByID(ctx context.Context, id uuid.UUID) (User, error) QueryByIDs(ctx context.Context, ids []uuid.UUID) ([]User, error) QueryByPhone(ctx context.Context, phone string) (User, error) }
Storer interface declares the behavior this package needs to perists and retrieve data.
Directories
¶
Path | Synopsis |
---|---|
stores
|
|
usercache
Package usercache contains user related CRUD functionality with caching.
|
Package usercache contains user related CRUD functionality with caching. |
userdb
Package userdb contains user related CRUD functionality.
|
Package userdb contains user related CRUD functionality. |