core — API Quick Reference
core — API Quick Reference
Section titled “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"AppConfig
Section titled “AppConfig”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}TLSConfig
Section titled “TLSConfig”type TLSConfig struct { Enabled bool CertFile string KeyFile string}RouterConfig
Section titled “RouterConfig”type RouterConfig struct { MethodNotAllowed bool}AppDependencies
Section titled “AppDependencies”type AppDependencies struct { Logger log.StructuredLogger}type App struct { /* unexported fields */ }Constructors
Section titled “Constructors”func New(cfg AppConfig, deps AppDependencies) *AppCreates 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.
DefaultConfig
Section titled “DefaultConfig”func DefaultConfig() AppConfigReturns a ready-to-use AppConfig with opinionated production defaults.
| Field | Default |
|---|---|
Addr | :8080 |
TLS.Enabled | false |
Router.MethodNotAllowed | false |
ReadTimeout | 30s |
ReadHeaderTimeout | 5s |
WriteTimeout | 30s |
IdleTimeout | 60s |
MaxHeaderBytes | 1 MiB (1 048 576 bytes) |
HTTP2Enabled | true |
DrainInterval | 500ms |
Route registration methods
Section titled “Route registration methods”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.Routefunc (a *App) Post(path string, handler http.Handler) *router.Routefunc (a *App) Put(path string, handler http.Handler) *router.RouteDelete
Section titled “Delete”func (a *App) Delete(path string, handler http.Handler) *router.Routefunc (a *App) Patch(path string, handler http.Handler) *router.Routefunc (a *App) Any(path string, handler http.Handler) *router.RouteRegisters the handler for all HTTP methods on the given path.
AddRoute
Section titled “AddRoute”func (a *App) AddRoute(method, path string, handler http.Handler, opts ...router.RouteOption) *router.RouteLow-level route registration. opts accepts router.WithRouteName(name) to enable reverse lookup.
func (a *App) Group(prefix string) *router.GroupReturns a route group that prepends prefix to all routes registered on the group.
Handle
Section titled “Handle”func (a *App) Handle(path string, handler http.Handler) *router.RouteRegisters an http.Handler (any method) at the given path.
Middleware
Section titled “Middleware”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).
Reverse routing
Section titled “Reverse routing”func (a *App) URL(name string, pairs ...string) stringResolves 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.
Lifecycle
Section titled “Lifecycle”Prepare
Section titled “Prepare”func (a *App) Prepare() errorFreezes the route table, applies middleware, and builds the handler chain. Must be called before Server. Returns a non-nil error if configuration is invalid.
Server
Section titled “Server”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.
Shutdown
Section titled “Shutdown”func (a *App) Shutdown(ctx context.Context) errorInitiates graceful shutdown. Drains in-flight connections at DrainInterval intervals until ctx is cancelled or all connections drain. Call with a deadline context.
Accessors
Section titled “Accessors”Logger
Section titled “Logger”func (a *App) Logger() log.StructuredLoggerReturns the logger passed in AppDependencies. Returns a no-op logger when none was provided.
Router
Section titled “Router”func (a *App) Router() *router.RouterReturns the underlying *router.Router. Use this to call Static, StaticFS, or Group when you need them on the router directly.
Path parameter syntax
Section titled “Path parameter syntax”| Syntax | Matches | Accessible via |
|---|---|---|
:name | Single path segment | router.Param(r, "name") |
*name | All remaining segments | router.Param(r, "name") |
See also
Section titled “See also”- Core Primer — boundary rationale, start-here checklist, ownership examples
- Router API Reference —
router.Router,Group,Param, static serving - Reference App — canonical bootstrap in
main.goandinternal/app/