howdah

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2025 License: MIT Imports: 26 Imported by: 0

README

Howdah

Howdah logo

Unstable/experimental library for creating elephant backoffice web UIs.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSkipRender = errors.New("skip render")

Functions

func HTTPErrorf

func HTTPErrorf(code int, message TextLabel, format string, a ...any) error

func InternalHTTPError

func InternalHTTPError(cause error) error

func LiteralHTTPError

func LiteralHTTPError(code int, err error) error

func NewHTTPError

func NewHTTPError(code int, msgID string, text string, cause error) error

func PT

func PT(loc *i18n.Localizer, msg *i18n.Message) string

func SortMenuItems

func SortMenuItems(menu []MenuItem)

SortMenuItems by weight.

Types

type AlterContext

type AlterContext[T any] struct {
	Request *http.Request
	Data    T
}

type Application

type Application struct {
	// contains filtered or unexported fields
}

func NewApplication

func NewApplication(
	logger *slog.Logger,
	httpMux *http.ServeMux,
	templates fs.FS,
	locales fs.FS,
	assets fs.FS,
	components []Component,
) (*Application, error)

func (*Application) Cleanup

func (a *Application) Cleanup()

func (*Application) GetMenu

func (a *Application) GetMenu() []MenuItem

type Authenticator

type Authenticator interface {
	RequireAuth(
		ctx context.Context, w http.ResponseWriter, r *http.Request,
	) (context.Context, error)
}

type Component

type Component interface {
	RegisterRoutes(mux *PageMux)
}

type ComponentObserver

type ComponentObserver interface {
	ObserveComponent(c Component)
}

type ErrorInfo

type ErrorInfo struct {
	Code    int
	Message TextLabel
	Error   error
}

type HTTPError

type HTTPError struct {
	Code    int
	Message TextLabel
	// contains filtered or unexported fields
}

func AsHTTPError

func AsHTTPError(err error) *HTTPError

func (*HTTPError) Error

func (h *HTTPError) Error() string

Error implements error.

func (*HTTPError) Unwrap

func (h *HTTPError) Unwrap() error

type HTTPHandlerFuncWithErr

type HTTPHandlerFuncWithErr func(w http.ResponseWriter, r *http.Request) error

func (HTTPHandlerFuncWithErr) ServeHTTP

type HTTPHandlerWithErr

type HTTPHandlerWithErr interface {
	ServeHTTP(w http.ResponseWriter, r *http.Request) error
}

type HookAlterFunc

type HookAlterFunc[D any, T any] func(ctx context.Context, data AlterContext[D], list []T) []T

type HookFunc

type HookFunc[T any] func() []T

type Hooks

type Hooks[D any, T any] struct {
	// contains filtered or unexported fields
}

func (*Hooks[D, T]) Alter

func (h *Hooks[D, T]) Alter(ctx context.Context, data AlterContext[D], list []T) []T

func (*Hooks[D, T]) Collect

func (h *Hooks[D, T]) Collect() []T

func (*Hooks[D, T]) RegisterAlter

func (h *Hooks[D, T]) RegisterAlter(fn HookAlterFunc[D, T])

func (*Hooks[D, T]) RegisterHook

func (h *Hooks[D, T]) RegisterHook(fn HookFunc[T])
type Link struct {
	Text TextLabel
	HREF string
}
type MenuHook interface {
	MenuHook(hooks *MenuHooks)
}
type MenuHooks = Hooks[Page, MenuItem]
type MenuItem struct {
	Title  TextLabel
	Active bool
	HREF   string
	Weight int
}

type OIDCAuth

type OIDCAuth struct {
	// contains filtered or unexported fields
}

func NewOIDCAuth

func NewOIDCAuth(
	provider *oidc.Provider,
	verifier *oidc.IDTokenVerifier,
	conf oauth2.Config,
) *OIDCAuth

func (*OIDCAuth) MenuHook

func (a *OIDCAuth) MenuHook(hooks *MenuHooks)

func (*OIDCAuth) OIDCUserInfo

func (a *OIDCAuth) OIDCUserInfo(ctx context.Context) (*oidc.UserInfo, error)

func (*OIDCAuth) RegisterRoutes

func (a *OIDCAuth) RegisterRoutes(mux *PageMux)

func (*OIDCAuth) RequireAuth

func (a *OIDCAuth) RequireAuth(
	ctx context.Context, w http.ResponseWriter, r *http.Request,
) (context.Context, error)

type OIDCUserInfoSource

type OIDCUserInfoSource interface {
	OIDCUserInfo(ctx context.Context) (*oidc.UserInfo, error)
}

type Page

type Page struct {
	Status     int
	Template   string
	Title      TextLabel
	Menu       []MenuItem
	Breadcrumb []Link
	Contents   any
}

type PageHandler

type PageHandler interface {
	ServePage(
		ctx context.Context, w http.ResponseWriter, r *http.Request,
	) (*Page, error)
}

type PageHandlerFunc

type PageHandlerFunc func(
	ctx context.Context, w http.ResponseWriter, r *http.Request,
) (*Page, error)

func (PageHandlerFunc) ServePage

func (fn PageHandlerFunc) ServePage(
	ctx context.Context, w http.ResponseWriter, r *http.Request,
) (*Page, error)

type PageMux

type PageMux struct {
	// contains filtered or unexported fields
}

func NewPageMux

func NewPageMux(
	r *PageRenderer,
	mux *http.ServeMux,
) *PageMux

func (*PageMux) Handle

func (pm *PageMux) Handle(pattern string, handler PageHandler)

func (*PageMux) HandleFunc

func (pm *PageMux) HandleFunc(pattern string, handler PageHandlerFunc)

type PageRenderer

type PageRenderer struct {
	// contains filtered or unexported fields
}

func NewPageRenderer

func NewPageRenderer(
	logger *slog.Logger,
	tplFs fs.FS, translations *i18n.Bundle,
	components []Component,
) (*PageRenderer, error)

func (*PageRenderer) ErrorPage

func (pr *PageRenderer) ErrorPage(
	ctx context.Context,
	w http.ResponseWriter, r *http.Request,
	info ErrorInfo,
)

func (*PageRenderer) Localizer

func (pr *PageRenderer) Localizer(r *http.Request) (string, *i18n.Localizer)

func (*PageRenderer) RenderPage

func (pr *PageRenderer) RenderPage(
	ctx context.Context,
	w http.ResponseWriter, r *http.Request,
	p *Page,
)

type TeplateFuncSource

type TeplateFuncSource interface {
	GetTemplateFuncs() template.FuncMap
}

type TextLabel

type TextLabel struct {
	Literal     string
	Message     *i18n.Message
	Values      any
	PluralCount *int
}

func TL

func TL(str string, forms ...string) TextLabel

func TLiteral

func TLiteral(str string) TextLabel

func TMsg

func TMsg(msg i18n.Message) TextLabel

Jump to

Keyboard shortcuts

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