Skip to content

core — API Quick Reference

This page lists every public symbol exported by github.com/spcent/plumego/core. Use it as a lookup when you already know the package; use the Core Primer when you need the boundary rationale and usage patterns.

import "github.com/spcent/plumego/core"

type AppConfig struct {
Addr string
TLS TLSConfig
Router RouterConfig
ReadTimeout time.Duration
ReadHeaderTimeout time.Duration
WriteTimeout time.Duration
IdleTimeout time.Duration
MaxHeaderBytes int
HTTP2Enabled bool
DrainInterval time.Duration
}
type TLSConfig struct {
Enabled bool
CertFile string
KeyFile string
}
type RouterConfig struct {
MethodNotAllowed bool
}
type AppDependencies struct {
Logger log.StructuredLogger
}
type App struct { /* unexported fields */ }

func New(cfg AppConfig, deps AppDependencies) *App

Creates and returns a new App. cfg is typically the result of DefaultConfig() with field overrides. deps carries optional shared dependencies (Logger); omit to discard logs.

func DefaultConfig() AppConfig

Returns a ready-to-use AppConfig with opinionated production defaults.

FieldDefault
Addr:8080
TLS.Enabledfalse
Router.MethodNotAllowedfalse
ReadTimeout30s
ReadHeaderTimeout5s
WriteTimeout30s
IdleTimeout60s
MaxHeaderBytes1 MiB (1 048 576 bytes)
HTTP2Enabledtrue
DrainInterval500ms

All route-registration methods are on *App. Each returns the registered *router.Route (returned value is typically discarded).

func (a *App) Get(path string, handler http.Handler) *router.Route
func (a *App) Post(path string, handler http.Handler) *router.Route
func (a *App) Put(path string, handler http.Handler) *router.Route
func (a *App) Delete(path string, handler http.Handler) *router.Route
func (a *App) Patch(path string, handler http.Handler) *router.Route
func (a *App) Any(path string, handler http.Handler) *router.Route

Registers the handler for all HTTP methods on the given path.

func (a *App) AddRoute(method, path string, handler http.Handler, opts ...router.RouteOption) *router.Route

Low-level route registration. opts accepts router.WithRouteName(name) to enable reverse lookup.

func (a *App) Group(prefix string) *router.Group

Returns a route group that prepends prefix to all routes registered on the group.

func (a *App) Handle(path string, handler http.Handler) *router.Route

Registers an http.Handler (any method) at the given path.


func (a *App) Use(middlewares ...func(http.Handler) http.Handler)

Appends middleware to the chain. Must be called before Prepare. Middleware runs in registration order (first registered = outermost).


func (a *App) URL(name string, pairs ...string) string

Resolves a named route to a URL. pairs alternates param name and value: app.URL("user-detail", "id", "42")"/api/users/42". Panics if the route name is not registered or param count is wrong.


func (a *App) Prepare() error

Freezes the route table, applies middleware, and builds the handler chain. Must be called before Server. Returns a non-nil error if configuration is invalid.

func (a *App) Server() (*http.Server, error)

Returns the configured *http.Server. Must be called after Prepare. The caller is responsible for ListenAndServe, ListenAndServeTLS, and Shutdown.

func (a *App) Run()

Combined convenience path: calls Prepare then starts the server with ListenAndServe (or ListenAndServeTLS when TLS is enabled). Logs a fatal error and exits on failure. Use Prepare + Server when you need to inspect the server before starting.

func (a *App) Shutdown(ctx context.Context) error

Initiates graceful shutdown. Drains in-flight connections at DrainInterval intervals until ctx is cancelled or all connections drain. Call with a deadline context.


func (a *App) Logger() log.StructuredLogger

Returns the logger passed in AppDependencies. Returns a no-op logger when none was provided.

func (a *App) Router() *router.Router

Returns the underlying *router.Router. Use this to call Static, StaticFS, or Group when you need them on the router directly.


SyntaxMatchesAccessible via
:nameSingle path segmentrouter.Param(r, "name")
*nameAll remaining segmentsrouter.Param(r, "name")