Documentation ¶
Index ¶
- Variables
- type AuthClient
- func (c *AuthClient) CheckPassword(password, hash string) error
- func (c *AuthClient) DeletePasswordTokens(ctx echo.Context, userID int) error
- func (c *AuthClient) GenerateEmailVerificationToken(email string) (string, error)
- func (c *AuthClient) GeneratePasswordResetToken(ctx echo.Context, userID int) (string, *ent.PasswordToken, error)
- func (c *AuthClient) GetAuthenticatedUser(ctx echo.Context) (*ent.User, error)
- func (c *AuthClient) GetAuthenticatedUserID(ctx echo.Context) (int, error)
- func (c *AuthClient) GetValidPasswordToken(ctx echo.Context, userID, tokenID int, token string) (*ent.PasswordToken, error)
- func (c *AuthClient) HashPassword(password string) (string, error)
- func (c *AuthClient) Login(ctx echo.Context, userID int) error
- func (c *AuthClient) Logout(ctx echo.Context) error
- func (c *AuthClient) RandomToken(length int) (string, error)
- func (c *AuthClient) ValidateEmailVerificationToken(token string) (string, error)
- type CacheClient
- type CacheFlushOp
- type CacheGetOp
- type CacheSetOp
- func (c *CacheSetOp) Data(data any) *CacheSetOp
- func (c *CacheSetOp) Expiration(expiration time.Duration) *CacheSetOp
- func (c *CacheSetOp) Group(group string) *CacheSetOp
- func (c *CacheSetOp) Key(key string) *CacheSetOp
- func (c *CacheSetOp) Save(ctx context.Context) error
- func (c *CacheSetOp) Tags(tags ...string) *CacheSetOp
- type CacheStore
- type CachedPage
- type Container
- type InvalidPasswordTokenError
- type MailClient
- type NotAuthenticatedError
- type TemplateParsed
- type TemplateRenderer
- type Validator
Constants ¶
This section is empty.
Variables ¶
var ErrCacheMiss = errors.New("cache miss")
ErrCacheMiss indicates that the requested key does not exist in the cache
Functions ¶
This section is empty.
Types ¶
type AuthClient ¶
type AuthClient struct {
// contains filtered or unexported fields
}
AuthClient is the client that handles authentication requests
func NewAuthClient ¶
func NewAuthClient(cfg *config.Config, orm *ent.Client) *AuthClient
NewAuthClient creates a new authentication client
func (*AuthClient) CheckPassword ¶
func (c *AuthClient) CheckPassword(password, hash string) error
CheckPassword check if a given password matches a given hash
func (*AuthClient) DeletePasswordTokens ¶
func (c *AuthClient) DeletePasswordTokens(ctx echo.Context, userID int) error
DeletePasswordTokens deletes all password tokens in the database for a belonging to a given user. This should be called after a successful password reset.
func (*AuthClient) GenerateEmailVerificationToken ¶
func (c *AuthClient) GenerateEmailVerificationToken(email string) (string, error)
GenerateEmailVerificationToken generates an email verification token for a given email address using JWT which is set to expire based on the duration stored in configuration
func (*AuthClient) GeneratePasswordResetToken ¶
func (c *AuthClient) GeneratePasswordResetToken(ctx echo.Context, userID int) (string, *ent.PasswordToken, error)
GeneratePasswordResetToken generates a password reset token for a given user. For security purposes, the token itself is not stored in the database but rather a hash of the token, exactly how passwords are handled. This method returns both the generated token as well as the token entity which only contains the hash.
func (*AuthClient) GetAuthenticatedUser ¶
func (c *AuthClient) GetAuthenticatedUser(ctx echo.Context) (*ent.User, error)
GetAuthenticatedUser returns the authenticated user if the user is logged in
func (*AuthClient) GetAuthenticatedUserID ¶
func (c *AuthClient) GetAuthenticatedUserID(ctx echo.Context) (int, error)
GetAuthenticatedUserID returns the authenticated user's ID, if the user is logged in
func (*AuthClient) GetValidPasswordToken ¶
func (c *AuthClient) GetValidPasswordToken(ctx echo.Context, userID, tokenID int, token string) (*ent.PasswordToken, error)
GetValidPasswordToken returns a valid, non-expired password token entity for a given user, token ID and token. Since the actual token is not stored in the database for security purposes, if a matching password token entity is found a hash of the provided token is compared with the hash stored in the database in order to validate.
func (*AuthClient) HashPassword ¶
func (c *AuthClient) HashPassword(password string) (string, error)
HashPassword returns a hash of a given password
func (*AuthClient) Login ¶
func (c *AuthClient) Login(ctx echo.Context, userID int) error
Login logs in a user of a given ID
func (*AuthClient) Logout ¶
func (c *AuthClient) Logout(ctx echo.Context) error
Logout logs the requesting user out
func (*AuthClient) RandomToken ¶
func (c *AuthClient) RandomToken(length int) (string, error)
RandomToken generates a random token string of a given length
func (*AuthClient) ValidateEmailVerificationToken ¶
func (c *AuthClient) ValidateEmailVerificationToken(token string) (string, error)
ValidateEmailVerificationToken validates an email verification token and returns the associated email address if the token is valid and has not expired
type CacheClient ¶
type CacheClient struct {
// contains filtered or unexported fields
}
CacheClient is the client that allows you to interact with the cache
func NewCacheClient ¶
func NewCacheClient(store CacheStore) *CacheClient
NewCacheClient creates a new cache client
func (*CacheClient) Flush ¶
func (c *CacheClient) Flush() *CacheFlushOp
Flush creates a cache flush operation
type CacheFlushOp ¶ added in v0.15.0
type CacheFlushOp struct {
// contains filtered or unexported fields
}
CacheFlushOp handles chaining a flush operation
func (*CacheFlushOp) Execute ¶ added in v0.15.0
func (c *CacheFlushOp) Execute(ctx context.Context) error
Execute flushes the data from the cache
func (*CacheFlushOp) Group ¶ added in v0.15.0
func (c *CacheFlushOp) Group(group string) *CacheFlushOp
Group sets the cache group
func (*CacheFlushOp) Key ¶ added in v0.15.0
func (c *CacheFlushOp) Key(key string) *CacheFlushOp
Key sets the cache key
func (*CacheFlushOp) Tags ¶ added in v0.15.0
func (c *CacheFlushOp) Tags(tags ...string) *CacheFlushOp
Tags sets the cache tags
type CacheGetOp ¶ added in v0.15.0
type CacheGetOp struct {
// contains filtered or unexported fields
}
CacheGetOp handles chaining a get operation
func (*CacheGetOp) Fetch ¶ added in v0.15.0
func (c *CacheGetOp) Fetch(ctx context.Context) (any, error)
Fetch fetches the data from the cache
func (*CacheGetOp) Group ¶ added in v0.15.0
func (c *CacheGetOp) Group(group string) *CacheGetOp
Group sets the cache group
func (*CacheGetOp) Key ¶ added in v0.15.0
func (c *CacheGetOp) Key(key string) *CacheGetOp
Key sets the cache key
type CacheSetOp ¶ added in v0.15.0
type CacheSetOp struct {
// contains filtered or unexported fields
}
CacheSetOp handles chaining a set operation
func (*CacheSetOp) Data ¶ added in v0.15.0
func (c *CacheSetOp) Data(data any) *CacheSetOp
Data sets the data to cache
func (*CacheSetOp) Expiration ¶ added in v0.15.0
func (c *CacheSetOp) Expiration(expiration time.Duration) *CacheSetOp
Expiration sets the expiration duration of the cached data
func (*CacheSetOp) Group ¶ added in v0.15.0
func (c *CacheSetOp) Group(group string) *CacheSetOp
Group sets the cache group
func (*CacheSetOp) Key ¶ added in v0.15.0
func (c *CacheSetOp) Key(key string) *CacheSetOp
Key sets the cache key
func (*CacheSetOp) Save ¶ added in v0.15.0
func (c *CacheSetOp) Save(ctx context.Context) error
Save saves the data in the cache
func (*CacheSetOp) Tags ¶ added in v0.15.0
func (c *CacheSetOp) Tags(tags ...string) *CacheSetOp
Tags sets the cache tags
type CacheStore ¶ added in v0.15.0
type CacheStore interface {
// contains filtered or unexported methods
}
CacheStore provides an interface for cache storage
type CachedPage ¶ added in v0.13.0
type CachedPage struct { // URL stores the URL of the requested page URL string // HTML stores the complete HTML of the rendered Page HTML []byte // StatusCode stores the HTTP status code StatusCode int // Headers stores the HTTP headers Headers map[string]string }
CachedPage is what is used to store a rendered Page in the cache
type Container ¶
type Container struct { // Validator stores a validator Validator *Validator // Web stores the web framework Web *echo.Echo // Config stores the application configuration Config *config.Config // Cache contains the cache client Cache *CacheClient // Database stores the connection to the database Database *sql.DB // ORM stores a client to the ORM ORM *ent.Client // Mail stores an email sending client Mail *MailClient // Auth stores an authentication client Auth *AuthClient // TemplateRenderer stores a service to easily render and cache templates TemplateRenderer *TemplateRenderer // Tasks stores the task client Tasks *backlite.Client }
Container contains all services used by the application and provides an easy way to handle dependency injection including within tests
func NewContainer ¶
func NewContainer() *Container
NewContainer creates and initializes a new Container
type InvalidPasswordTokenError ¶
type InvalidPasswordTokenError struct{}
InvalidPasswordTokenError is an error returned when an invalid token is provided
func (InvalidPasswordTokenError) Error ¶
func (e InvalidPasswordTokenError) Error() string
Error implements the error interface.
type MailClient ¶
type MailClient struct {
// contains filtered or unexported fields
}
MailClient provides a client for sending email This is purposely not completed because there are many different methods and services for sending email, many of which are very different. Choose what works best for you and populate the methods below
func NewMailClient ¶
func NewMailClient(cfg *config.Config, templates *TemplateRenderer) (*MailClient, error)
NewMailClient creates a new MailClient
type NotAuthenticatedError ¶
type NotAuthenticatedError struct{}
NotAuthenticatedError is an error returned when a user is not authenticated
func (NotAuthenticatedError) Error ¶
func (e NotAuthenticatedError) Error() string
Error implements the error interface.
type TemplateParsed ¶
type TemplateParsed struct { // Template is the parsed template Template *template.Template // contains filtered or unexported fields }
TemplateParsed is a wrapper around parsed templates which are stored in the TemplateRenderer cache
type TemplateRenderer ¶
type TemplateRenderer struct {
// contains filtered or unexported fields
}
TemplateRenderer provides a flexible and easy to use method of rendering simple templates or complex sets of templates while also providing caching and/or hot-reloading depending on your current environment
func NewTemplateRenderer ¶
func NewTemplateRenderer(cfg *config.Config, cache *CacheClient, fm template.FuncMap) *TemplateRenderer
NewTemplateRenderer creates a new TemplateRenderer
func (*TemplateRenderer) GetCachedPage ¶ added in v0.13.0
func (t *TemplateRenderer) GetCachedPage(ctx echo.Context, url string) (*CachedPage, error)
GetCachedPage attempts to fetch a cached page for a given URL
func (*TemplateRenderer) Load ¶
func (t *TemplateRenderer) Load(group, key string) (*TemplateParsed, error)
Load loads a template from the cache
func (*TemplateRenderer) Parse ¶
func (t *TemplateRenderer) Parse() *templateBuilder
Parse creates a template build operation
func (*TemplateRenderer) RenderPage ¶ added in v0.13.0
func (t *TemplateRenderer) RenderPage(ctx echo.Context, page page.Page) error
RenderPage renders a Page as an HTTP response