Documentation
¶
Index ¶
- Constants
- func RenderTemplate(templatePath string, layoutPath string, inlineJS string, moduleSrc string, ...) (string, error)
- type APIResponse
- type ApiRoute
- type Engine
- type PageRoute
- type Request
- type SecurityLayer
- type Server
- func (s *Server) Api(route ApiRoute)
- func (s *Server) AssetOptimizationEnabled() bool
- func (s *Server) Page(route PageRoute)
- func (s *Server) Security(layer SecurityLayer)
- func (s *Server) Serve(port int) error
- func (s *Server) SetAssetOptimization(enabled bool)
- func (s *Server) SetDefaultLayout(path string)
Constants ¶
const DevWebSocketPort = 35729
DevWebSocketPort is the fixed port the bungo CLI listens on for live reload; must match injected client.
Variables ¶
This section is empty.
Functions ¶
func RenderTemplate ¶
func RenderTemplate( templatePath string, layoutPath string, inlineJS string, moduleSrc string, data map[string]any, ) (string, error)
RenderTemplate renders a page template, optionally composed inside a layout template. Inputs: - templatePath: required path to the page-specific .gohtml template file. - layoutPath: optional wrapper .gohtml path that defines {{block "content" .}}. - inlineJS: compiled JavaScript source to inject inline as a module script. - moduleSrc: optional static module URL injected when asset optimization is enabled. - data: template data passed to Execute after BunGo script fields are merged in. Outputs: - string: fully rendered HTML with BunGo data/scripts injected into template output. - error: non-nil when template files cannot be read, parsed, or executed.
Types ¶
type APIResponse ¶
APIResponse represents an API response
type ApiRoute ¶
type ApiRoute struct {
Path string
Version string
Method string
SecurityLayer []string
Handler func(req *Request) (APIResponse, error)
}
ApiRoute represents a configuration for an API route
type Engine ¶
Invoker represents the execution environment starting the server. We define it locally to avoid import cycle, since engine pkg depends on bungo
type PageRoute ¶
type PageRoute struct {
Path string
Template string
Layout string
View string
SecurityLayer []string
Handler func(req *Request) (map[string]any, error)
}
PageRoute configures a single page route.
Template is required: the page-specific .gohtml file in layouts/ that holds the page content (and optionally {{define "content"}} when using a Layout).
Layout is optional: a wrapper .gohtml in layouts/ that defines {{block "content" .}}. When set, the Template is rendered inside that block, so you avoid repeating <html>, <head>, and <body> in every template. If empty, the Template is rendered as a standalone page.
View is optional: the corresponding .jsx/.tsx (or .js/.ts) entry in views/ to be compiled and injected into the page as a module script.
type Request ¶
type Request struct {
Headers map[string]string
Params map[string]string // URL and Query parameters
Body []byte
Internal map[string]any // For passing context between Security Layers and Handlers
}
Request represents a framework-agnostic HTTP request
type SecurityLayer ¶
SecurityLayer represents a reusable security layer that can be applied to routes.
type Server ¶
type Server struct {
Pages map[string]PageRoute
APIs map[string]ApiRoute
SecurityLayers map[string]SecurityLayer
Engine Engine
WebDir string
DefaultLayout string
// contains filtered or unexported fields
}
Server is the central registry for the BunGo application.
func NewServer ¶
NewServer creates a Server and validates required web directory structure at startup. Inputs: - engine: runtime engine implementation responsible for serving incoming requests. - webDir: base web directory containing required layouts/ and views/ subdirectories. Outputs: - *Server: initialized server registry with empty route and security maps.
func (*Server) Api ¶
Api registers an API route in the server route registry. Inputs: - route: API route configuration keyed by version, method, and path. Outputs: - none
func (*Server) AssetOptimizationEnabled ¶ added in v0.2.0
AssetOptimizationEnabled reports whether static module bundle delivery is enabled. Inputs: - none Outputs: - bool: true when SetAssetOptimization enabled external /_bungo bundle serving.
func (*Server) Page ¶
Page registers a page route and validates referenced template, layout, and view files. Inputs: - route: page route configuration to store in the server route registry. Outputs: - none
func (*Server) Security ¶
func (s *Server) Security(layer SecurityLayer)
Security registers a named security layer in the server security registry. Inputs: - layer: reusable security layer definition with name and handler function. Outputs: - none
func (*Server) Serve ¶
Serve starts server execution on the provided port using the configured engine. Inputs: - port: TCP port number used to build the engine listen address. Outputs: - error: non-nil when the engine fails to start or returns a runtime error.
func (*Server) SetAssetOptimization ¶ added in v0.2.0
SetAssetOptimization toggles static module delivery for compiled page view bundles. Inputs: - enabled: true to serve view bundles via /_bungo/*.js, false to inline module code. Outputs: - none
func (*Server) SetDefaultLayout ¶
SetDefaultLayout sets the default layout file used when a page route omits Layout. Inputs: - path: layout filename in webDir/layouts, or empty string to clear the default. Outputs: - none
