trails

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindBody

func BindBody(c *Context, dst any) error

func BindPathParams

func BindPathParams(c *Context, dst any) error

func BindQueryParams

func BindQueryParams(c *Context, dst any) error

func Environment

func Environment() string

func LoadConfig

func LoadConfig[T any](environment string, configFS fs.FS) (*T, error)

func MergeFS

func MergeFS(roots ...fs.FS) fs.FS

func MergeSpurAssets

func MergeSpurAssets(hostAssets fs.FS, mounts ...Mount) fs.FS

func MergeSpurManifests

func MergeSpurManifests(hostManifest assets.Manifest, mounts ...Mount) (assets.Manifest, error)

func MergeSpurViews

func MergeSpurViews(hostViews fs.FS, mounts ...Mount) fs.FS

func RegisterSpurJobs

func RegisterSpurJobs(reg *jobs.Registry, mounts ...Mount)

func RegisterSpurRoutes

func RegisterSpurRoutes(r *Router, mounts ...Mount)

Types

type AssetsStrategy

type AssetsStrategy string
const (
	AssetsStrategyImportMap AssetsStrategy = "importmap"
	AssetsStrategyBundler   AssetsStrategy = "bundler"
	AssetsStrategyNone      AssetsStrategy = "none"
)

type Binder

type Binder interface {
	Bind(c *Context, target any) error
}

type Context

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

func (*Context) Bind

func (c *Context) Bind(target any) error

func (*Context) Blob

func (c *Context) Blob(code int, contentType string, b []byte) error

func (*Context) Context

func (c *Context) Context() context.Context

func (*Context) Get

func (c *Context) Get[T any](key string) T

func (*Context) HTML

func (c *Context) HTML(code int, html string) error

func (*Context) HTMLBlob

func (c *Context) HTMLBlob(code int, blob []byte) error

func (*Context) JSON

func (c *Context) JSON(code int, j any) error

func (*Context) Logger

func (c *Context) Logger() *slog.Logger

func (*Context) Render

func (c *Context) Render(code int, name string, data any) error

func (*Context) Request

func (c *Context) Request() *http.Request

func (*Context) Reset

func (c *Context) Reset(w http.ResponseWriter, r *http.Request)

func (*Context) Response

func (c *Context) Response() http.ResponseWriter

func (*Context) Set

func (c *Context) Set(key string, val any)

func (*Context) String

func (c *Context) String(code int, s string) error

type DefaultBinder

type DefaultBinder struct{}

func (*DefaultBinder) Bind

func (d *DefaultBinder) Bind(c *Context, target any) error

type ErrorHandlerFunc

type ErrorHandlerFunc func(c *Context, err HTTPError)

type Group

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

func (*Group) Delete

func (g *Group) Delete(pattern string, h HandlerFunc)

func (*Group) Get

func (g *Group) Get(pattern string, h HandlerFunc)

func (*Group) HandleFunc

func (g *Group) HandleFunc(method, pattern string, h HandlerFunc)

func (*Group) NewGroup

func (g *Group) NewGroup(prefix string, mws ...MiddlewareFunc) *Group

func (*Group) Patch

func (g *Group) Patch(pattern string, h HandlerFunc)

func (*Group) Post

func (g *Group) Post(pattern string, h HandlerFunc)

func (*Group) Put

func (g *Group) Put(pattern string, h HandlerFunc)

func (*Group) Resource

func (g *Group) Resource(prefix string, r Resource, mw ...MiddlewareFunc)

func (*Group) Resources

func (g *Group) Resources(prefix string, r Resources, mw ...MiddlewareFunc)

func (*Group) Use

func (g *Group) Use(mws ...MiddlewareFunc)

func (*Group) WithGroup

func (g *Group) WithGroup(prefix string, fn GroupBuilder, mws ...MiddlewareFunc)

type GroupBuilder

type GroupBuilder func(g *Group)

type HTTPError

type HTTPError interface {
	error
	StatusCode() int
}

func NewHTTPError

func NewHTTPError(code int, err error) HTTPError

type HandlerFunc

type HandlerFunc func(c *Context) error

type MiddlewareFunc

type MiddlewareFunc func(next HandlerFunc) HandlerFunc

type Mount

type Mount struct {
	Prefix string
	Spur   Spur
}

type Renderer

type Renderer interface {
	Render(c *Context, w io.Writer, name string, data any) error
}

type Resource

type Resource interface {
	New(c *Context) error
	Create(c *Context) error
	Show(c *Context) error
	Edit(c *Context) error
	Update(c *Context) error
	Destroy(c *Context) error
}

type Resources

type Resources interface {
	Resource
	Index(c *Context) error
}

type RouteBuilder

type RouteBuilder func(r *Router)

type Router

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

func (*Router) Delete

func (rt *Router) Delete(pattern string, h HandlerFunc)

func (*Router) Get

func (rt *Router) Get(pattern string, h HandlerFunc)

func (*Router) HandleFunc

func (rt *Router) HandleFunc(method, pattern string, h HandlerFunc)

func (*Router) NewGroup

func (rt *Router) NewGroup(prefix string, mws ...MiddlewareFunc) *Group

func (*Router) Patch

func (rt *Router) Patch(pattern string, h HandlerFunc)

func (*Router) Post

func (rt *Router) Post(pattern string, h HandlerFunc)

func (*Router) Put

func (rt *Router) Put(pattern string, h HandlerFunc)

func (*Router) Resource

func (rt *Router) Resource(prefix string, r Resource, mw ...MiddlewareFunc)

func (*Router) Resources

func (rt *Router) Resources(prefix string, r Resources, mw ...MiddlewareFunc)

func (*Router) ServeHTTP

func (rt *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Router) Use

func (rt *Router) Use(mws ...MiddlewareFunc)

func (*Router) WithGroup

func (rt *Router) WithGroup(prefix string, fn GroupBuilder, mws ...MiddlewareFunc)

type Runner

type Runner interface {
	Run(ctx context.Context) error
}

Runner is a background loop a host app needs kept alive alongside the HTTP server — e.g. a polling Broadcaster's delivery loop, or a jobs.Backend's worker loop. Run must return once ctx is cancelled; see Trail.Run and RegisterSpurRunners.

func RegisterSpurRunners

func RegisterSpurRunners(mounts ...Mount) []Runner

RegisterSpurRunners collects the background Runner for every mounted Spur that has one (e.g. a channels.Backend wrapping a polling Broadcaster). Spurs with nothing to run are silently skipped. Pass the result as TrailOptions.Runners so Trail.Run starts and stops them alongside the HTTP server.

type Spur

type Spur interface {
	ViewFS() fs.FS
	AssetsFS() fs.FS
	Routes(g *Group)
	Jobs(r *jobs.Registry)
}

type Trail

type Trail struct {
	Host string
	Port int
	// contains filtered or unexported fields
}

func New

func New(o *TrailOptions) (*Trail, error)

func (*Trail) Run

func (t *Trail) Run() error

func (*Trail) ServeHTTP

func (t *Trail) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Trail) Use

func (t *Trail) Use(mws ...MiddlewareFunc)

type TrailOptions

type TrailOptions struct {
	Context        context.Context
	Logger         *slog.Logger
	ViewFS         fs.FS
	AssetsFS       fs.FS
	ConfigFS       fs.FS
	ErrorHandler   ErrorHandlerFunc
	RouteBuilder   RouteBuilder
	Renderer       Renderer
	Binder         Binder
	LayoutName     string
	Host           string
	Port           int
	AssetsStrategy AssetsStrategy
	// Runners are started as background goroutines alongside the HTTP
	// server by Trail.Run, and stopped on the same shutdown signal —
	// typically built via RegisterSpurRunners(mounts...).
	Runners []Runner
}

func WithDefaultOptions

func WithDefaultOptions(opts *TrailOptions) *TrailOptions

type Unmarshaler

type Unmarshaler interface {
	UnmarshalParam(value string) error
}

Jump to

Keyboard shortcuts

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