Documentation
¶
Index ¶
- type APIError
- type APIRoute
- type ActionFunc
- type App
- func (app *App) API(method, pattern string, route APIRoute)
- func (app *App) APIDelete(pattern string, route APIRoute)
- func (app *App) APIGet(pattern string, route APIRoute)
- func (app *App) APIPatch(pattern string, route APIRoute)
- func (app *App) APIPost(pattern string, route APIRoute)
- func (app *App) APIPut(pattern string, route APIRoute)
- func (app *App) Close() error
- func (app *App) Delete(pattern string, route Route)
- func (app *App) GenerateTypes() error
- func (app *App) Get(pattern string, route Route)
- func (app *App) Group(prefix, layout string, fn func(g *Group))
- func (app *App) Handler() http.Handler
- func (app *App) Island(name, tsxPath string)
- func (app *App) Patch(pattern string, route Route)
- func (app *App) Post(pattern string, route Route)
- func (app *App) Put(pattern string, route Route)
- func (app *App) RecoverWithErrorPage() MiddlewareFunc
- func (app *App) Static(urlPrefix, dir string)
- func (app *App) Use(mw MiddlewareFunc)
- type AuthOption
- type Context
- type CookieOption
- type FieldError
- type Group
- func (g *Group) API(method, pattern string, route APIRoute)
- func (g *Group) APIDelete(pattern string, route APIRoute)
- func (g *Group) APIGet(pattern string, route APIRoute)
- func (g *Group) APIPatch(pattern string, route APIRoute)
- func (g *Group) APIPost(pattern string, route APIRoute)
- func (g *Group) APIPut(pattern string, route APIRoute)
- func (g *Group) Delete(pattern string, route Route)
- func (g *Group) Get(pattern string, route Route)
- func (g *Group) Group(prefix, layout string, fn func(g *Group))
- func (g *Group) Patch(pattern string, route Route)
- func (g *Group) Post(pattern string, route Route)
- func (g *Group) Put(pattern string, route Route)
- func (g *Group) Use(mw MiddlewareFunc)
- type HandlerFunc
- type HeadData
- type LoaderFunc
- type MetaTag
- type MiddlewareFunc
- type Option
- func WithDependencies(pkgs ...string) Option
- func WithDevMode(enabled bool) Option
- func WithErrorComponent(file string) Option
- func WithLayout(file string) Option
- func WithNotFoundComponent(file string) Option
- func WithPoolSize(n int) Option
- func WithSSRCache(maxEntries int) Option
- func WithStreaming(enabled bool) Option
- func WithTemplateDir(dir string) Option
- type Route
- type Session
- type SessionOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
APIError represents an error with an HTTP status code for API responses.
func NewAPIError ¶
NewAPIError creates an APIError with the given status code and message.
type APIRoute ¶
type APIRoute struct {
Handler HandlerFunc
}
APIRoute defines a handler for a JSON API endpoint.
type ActionFunc ¶
ActionFunc handles mutations (e.g., form submissions).
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is the main dark application.
func (*App) GenerateTypes ¶
GenerateTypes generates TypeScript type definitions from Props fields on registered routes. Output is written to <templateDir>/_generated/props.d.ts.
func (*App) Group ¶
Group creates a route group with a shared URL prefix and layout. All routes registered within the group inherit the layout. Nested groups compose layouts from outer to inner.
func (*App) RecoverWithErrorPage ¶
func (app *App) RecoverWithErrorPage() MiddlewareFunc
RecoverWithErrorPage returns a middleware that recovers from panics and renders the configured error page. Use this instead of Recover() to get custom error pages.
type AuthOption ¶
type AuthOption func(*authConfig)
AuthOption configures the RequireAuth middleware.
func AuthCheck ¶
func AuthCheck(fn func(*Session) bool) AuthOption
AuthCheck sets a custom function to determine if a session is authenticated. When set, this overrides the default session key check.
func AuthLoginURL ¶
func AuthLoginURL(url string) AuthOption
AuthLoginURL sets the URL to redirect unauthenticated users to (default "/login").
func AuthSessionKey ¶
func AuthSessionKey(key string) AuthOption
AuthSessionKey sets the session key to check for authentication (default "user").
type Context ¶
type Context interface {
Request() *http.Request
ResponseWriter() http.ResponseWriter
Param(name string) string
Query(name string) string
FormData() url.Values
Redirect(url string) error
RenderError(err error) error
SetHeader(key, value string)
JSON(status int, data any) error
BindJSON(v any) error
AddFieldError(field, message string)
HasErrors() bool
FieldErrors() []FieldError
SetTitle(title string)
AddMeta(name, content string)
AddOpenGraph(property, content string)
SetCookie(name, value string, opts ...CookieOption)
GetCookie(name string) (string, error)
DeleteCookie(name string)
Session() *Session
}
Context provides access to the request, response, and route parameters.
type CookieOption ¶
type CookieOption func(*cookieConfig)
CookieOption configures a cookie set via Context.SetCookie.
func CookieHTTPOnly ¶
func CookieHTTPOnly(enabled bool) CookieOption
CookieHTTPOnly sets the HttpOnly flag (default true).
func CookieMaxAge ¶
func CookieMaxAge(seconds int) CookieOption
CookieMaxAge sets the cookie max age in seconds. 0 means session cookie.
func CookiePath ¶
func CookiePath(path string) CookieOption
CookiePath sets the cookie path (default "/").
func CookieSameSite ¶
func CookieSameSite(mode http.SameSite) CookieOption
CookieSameSite sets the SameSite attribute (default Lax).
type FieldError ¶
FieldError represents a validation error for a specific form field.
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group defines a set of routes that share a common URL prefix, layout, and middleware.
func (*Group) Use ¶
func (g *Group) Use(mw MiddlewareFunc)
Use adds a middleware to the group. It applies only to routes in this group and any nested groups.
type HeadData ¶
type HeadData struct {
Title string `json:"title,omitempty"`
Meta []MetaTag `json:"meta,omitempty"`
}
HeadData holds metadata for the HTML <head> section.
type LoaderFunc ¶
LoaderFunc fetches data for a route. The returned value is passed as props to the TSX component.
type MetaTag ¶
type MetaTag struct {
Name string `json:"name,omitempty"`
Property string `json:"property,omitempty"`
Content string `json:"content"`
}
MetaTag represents a <meta> element.
type MiddlewareFunc ¶
MiddlewareFunc is a standard Go HTTP middleware.
func Recover ¶
func Recover() MiddlewareFunc
Recover returns a middleware that recovers from panics and returns a 500 response.
func RequireAuth ¶
func RequireAuth(opts ...AuthOption) MiddlewareFunc
RequireAuth returns a middleware that redirects unauthenticated users to the login page. It requires the Sessions middleware to be applied first.
Usage:
app.Group("/admin", "layouts/admin.tsx", func(g *dark.Group) {
g.Use(dark.RequireAuth())
g.Get("/dashboard", dark.Route{...})
})
func Sessions ¶
func Sessions(secret []byte, opts ...SessionOption) MiddlewareFunc
Sessions returns a middleware that provides cookie-based sessions with HMAC signing. The secret is used to sign and verify session cookies.
type Option ¶
type Option func(*config)
Option configures the dark application.
func WithDependencies ¶
WithDependencies adds additional npm dependencies beyond preact.
func WithDevMode ¶
WithDevMode enables development mode with cache invalidation on file changes.
func WithErrorComponent ¶
WithErrorComponent sets a TSX component for rendering 500 error pages.
func WithLayout ¶
WithLayout sets the layout TSX file path relative to the template directory.
func WithNotFoundComponent ¶
WithNotFoundComponent sets a TSX component for rendering 404 pages.
func WithPoolSize ¶
WithPoolSize sets the number of ramune RuntimePool workers.
func WithSSRCache ¶
WithSSRCache enables SSR output caching. maxEntries sets the maximum number of cached component+props combinations. When the cache is full, it is cleared. 0 (default) disables caching.
func WithStreaming ¶
WithStreaming enables streaming SSR (shell-first rendering for faster TTFB).
func WithTemplateDir ¶
WithTemplateDir sets the directory for TSX template files.
type Route ¶
type Route struct {
Component string // TSX file path relative to the template directory
Loader LoaderFunc // data loader
Action ActionFunc // mutation handler
Layout string // layout TSX file path relative to the template directory (nests inside global layout)
Streaming *bool // nil = use global default, true/false = per-route override
Props any // optional: Go struct zero value for TypeScript type generation
}
Route defines a handler for a URL pattern with SSR rendering.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session holds per-request session data backed by a signed cookie.
func (*Session) Flashes ¶
Flashes returns and clears all flash messages from the previous request. Returns nil if there are no flashes.
type SessionOption ¶
type SessionOption func(*sessionConfig)
SessionOption configures the session middleware.
func SessionHTTPOnly ¶
func SessionHTTPOnly(enabled bool) SessionOption
SessionHTTPOnly sets the HttpOnly flag on the session cookie (default true).
func SessionMaxAge ¶
func SessionMaxAge(seconds int) SessionOption
SessionMaxAge sets the session max age in seconds (default 86400 = 1 day).
func SessionName ¶
func SessionName(name string) SessionOption
SessionName sets the session cookie name (default "_dark_session").
func SessionPath ¶
func SessionPath(path string) SessionOption
SessionPath sets the session cookie path (default "/").
func SessionSameSite ¶
func SessionSameSite(mode http.SameSite) SessionOption
SessionSameSite sets the SameSite attribute on the session cookie (default Lax).
func SessionSecure ¶
func SessionSecure(enabled bool) SessionOption
SessionSecure sets the Secure flag on the session cookie.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
_examples
|
|
|
database
command
Example: dark + SQLite database integration
|
Example: dark + SQLite database integration |
|
deploy/cmd/server
command
Production-ready dark application entry point.
|
Production-ready dark application entry point. |
|
hello
command
|