composables

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2024 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSessionFound = errors.New("no session found")
	ErrNoUserFound    = errors.New("no user found")
)
View Source
var (
	ErrLocalizerNotFound = errors.New("localizer not found")
)
View Source
var (
	ErrNavItemsNotFound = errors.New("navigation items not found")
)
View Source
var (
	ErrNoHeadFound = errors.New("no head found")
)

Functions

func CanUser

func CanUser(ctx context.Context, permission permission.Permission) error

func MustUseHead added in v0.0.2

func MustUseHead(ctx context.Context) types.HeadComponent

MustUseHead returns the head component from the context or panics

func MustUseLogo(ctx context.Context) templ.Component

MustUseLogo returns the logo component from the context or panics

func UseAuthenticated

func UseAuthenticated(ctx context.Context) bool

UseAuthenticated returns whether the user is authenticated and the second return value is true. If the user is not authenticated, the second return value is false.

func UseHead added in v0.0.2

func UseHead(ctx context.Context) (types.HeadComponent, error)

UseHead returns the head component from the context

func UseIP

func UseIP(ctx context.Context) (string, bool)

UseIP returns the IP address from the context. If the IP address is not found, the second return value will be false.

func UseLocale

func UseLocale(ctx context.Context, defaultLocale language.Tag) language.Tag

UseLocale returns the locale from the context. If the locale is not found, the second return value will be false.

func UseLocalizedOrFallback

func UseLocalizedOrFallback(ctx context.Context, key string, fallback string) string

func UseLocalizer

func UseLocalizer(ctx context.Context) (*i18n.Localizer, bool)

UseLocalizer returns the localizer from the context. If the localizer is not found, the second return value will be false.

func UseLogger

func UseLogger(ctx context.Context) (*log.Logger, bool)

UseLogger returns the logger from the context. If the logger is not found, the second return value will be false.

func UseLogo(ctx context.Context) (templ.Component, error)

UseLogo returns the logo component from the context

func UseMeta

func UseMeta(ctx context.Context) (map[string]interface{}, bool)

UseMeta returns the metadata from the context. If the metadata is not found, the second return value will be false.

func UseNavItems

func UseNavItems(r *http.Request) ([]types.NavigationItem, error)

func UsePageCtx

func UsePageCtx(r *http.Request, pageData *types.PageData) (*types.PageContext, error)

func UseRequest

func UseRequest(ctx context.Context) (*http.Request, bool)

UseRequest returns the request from the context. If the request is not found, the second return value will be false.

func UseSession

func UseSession(ctx context.Context) (*session.Session, error)

UseSession returns the session from the context.

func UseTx

func UseTx(ctx context.Context) (*gorm.DB, bool)

UseTx returns the database transaction from the context. If the transaction is not found, the second return value will be false.

func UseUniLocalizer

func UseUniLocalizer(ctx context.Context) (ut.Translator, bool)

func UseUser

func UseUser(ctx context.Context) (*user.User, error)

UseUser returns the user from the context.

func UseUserAgent

func UseUserAgent(ctx context.Context) (string, bool)

UseUserAgent returns the user agent from the context. If the user agent is not found, the second return value will be false.

func UseWriter

func UseWriter(ctx context.Context) (http.ResponseWriter, bool)

UseWriter returns the response writer from the context. If the response writer is not found, the second return value will be false.

func WithParams

func WithParams(ctx context.Context, params *Params) context.Context

WithParams returns a new context with the request parameters.

func WithTx

func WithTx(ctx context.Context, tx *gorm.DB) context.Context

WithTx returns a new context with the database transaction.

Types

type PaginationParams

type PaginationParams struct {
	Limit  int
	Offset int
	Page   int
}

func UsePaginated

func UsePaginated(r *http.Request) PaginationParams

type Params

type Params struct {
	IP            string
	UserAgent     string
	Authenticated bool
	Request       *http.Request
	Writer        http.ResponseWriter
	Meta          map[string]interface{}
}

func UseParams

func UseParams(ctx context.Context) (*Params, bool)

UseParams returns the request parameters from the context. If the parameters are not found, the second return value will be false.

Jump to

Keyboard shortcuts

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