Documentation
¶
Index ¶
- Variables
- func Hash(str string) string
- func ParseConditionable[T Conditionable](v string) (any, error)
- func ValidateOp[T Conditionable](op Op, value T, values ...T) error
- type Cond
- type Condition
- type Conditionable
- type Filter
- type Iterator
- type Op
- type OrdBy
- type OrdDir
- type Order
- type PageParams
- type PaginationData
- type Password
- type Passworder
- type ReprCondition
- type Store
- type User
- type UserData
Constants ¶
This section is empty.
Variables ¶
var ErrNoMorePages = errors.New("the iterator has been consumed")
Functions ¶
func ParseConditionable ¶
func ParseConditionable[T Conditionable](v string) (any, error)
ParseConditionable tries to transform a value in a string condition into the specified type T. The following mapping from strings are supported:
- string -> string
- int -> int
- time.RFC3339 -> time.Time
func ValidateOp ¶
func ValidateOp[T Conditionable](op Op, value T, values ...T) error
Types ¶
type Cond ¶
type Cond[T Conditionable] struct { Op Value T Values []T }
func ParseCondition ¶
func ParseCondition[T Conditionable](c string) (cond Cond[T], err error)
ParseCondition tries to parse a string into a condition, matching on it and trying to cast the match into the proper Cond[T].
type Condition ¶
type Condition[T Conditionable] interface { // Evaluate translates the abstract Condition into a form that is // usable by the backend. Evaluate(field string) (any, error) // Hash returns a unique identified deterministically derived by the // values of the condition. Hash(field string) (string, error) }
Condition is the interface any backend will need to implement in order to translate the given condition in a valid expression for the backend at hand.
type Conditionable ¶
type Conditionable interface {
constraints.Integer | constraints.Float | string | time.Time
}
type Filter ¶
type Filter struct {
Id string
FirstName Condition[string]
LastName Condition[string]
NickName Condition[string]
Email Condition[string]
Country Condition[string]
CreatedAt Condition[time.Time]
UpdatedAt Condition[time.Time]
}
Filter is a condition to be used to filter users. The backend type represents the output type a concrete implementation will produce as output of the evaluation of the filter.
func ParseFilter ¶
ParseFilter takes an optional map with a set of conditions to be parsed and, upon successful parsing of each condition, returns a *Filter.
type Iterator ¶
type Iterator[T any] interface { // Len returns some data regarding the pagination. Len() PaginationData // Next returns the next page. It returns ErrNoMorePages after the last page. Next(ctx context.Context) (T, error) }
Iterator is the interface to iterate over the results.
type Order ¶
func ParseOrder ¶
type PageParams ¶
PageParams conveys the information needed to specify a page for the Page method.
type PaginationData ¶
PaginationData regards the global information pertaining the pagination.
type Password ¶
type Password []byte
Password represents a secret to be stored safely at rest.
func NewPassword ¶
type Passworder ¶
type ReprCondition ¶
type ReprCondition[T Conditionable] Cond[T]
type Store ¶
type Store interface {
Add(ctx context.Context, user *UserData) (*User, error)
Update(ctx context.Context, id string, user *UserData) (*User, error)
Remove(ctx context.Context, id string) (*User, error)
List(ctx context.Context, filter *Filter, pageSize uint) (Iterator[[]*User], error)
Page(ctx context.Context, filter *Filter, params *PageParams) ([]*User, error)
}
Store represents the storage backend for the Users.
type User ¶
type User struct {
Id string `json:"id"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
NickName string `json:"nickname"`
Password Password `json:"-"`
Email string `json:"email"`
Country string `json:"country"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
User is the main entity we handle, it contains all the needed information
type UserData ¶
type UserData struct {
FirstName string `json:"first_name,omitempty"`
LastName string `json:"last_name,omitempty"`
NickName string `json:"nickname,omitempty"`
Password string `json:"password,omitempty"`
Email string `json:"email,omitempty"`
Country string `json:"country,omitempty"`
}
UserData represents the data needed to create or alter a user.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
userz
command
|
|
|
pollednotifier
command
|
|
|
pkg
|
|
|
notifier
The notifier package
|
The notifier package |
|
proto
This package holds the gRPC definitions and generated code
|
This package holds the gRPC definitions and generated code |
|
store
|
|