Documentation
¶
Overview ¶
Package wave provides runtime services for Wave applications. Build-time and dev-time functionality is in the wave/tooling subpackage.
Index ¶
- Constants
- Variables
- func GetIsDev() bool
- func GetPort() int
- func GetRefreshServerPort() int
- func MustGetPort() int
- func RefreshScriptInner(port int) string
- func SetModeToDev()
- func SetPort(port int)
- func SetRefreshServerPort(port int)
- type CSSEntryFiles
- type Config
- type CoreConfig
- type DistLayout
- func (d DistLayout) Binary() string
- func (d DistLayout) CriticalCSS() string
- func (d DistLayout) Internal() string
- func (d DistLayout) KeepFile() string
- func (d DistLayout) NormalCSSRef() string
- func (d DistLayout) PrivateFileMapGob() string
- func (d DistLayout) PublicFileMapGob() string
- func (d DistLayout) PublicFileMapRef() string
- func (d DistLayout) Static() string
- func (d DistLayout) StaticAssets() string
- func (d DistLayout) StaticPrivate() string
- func (d DistLayout) StaticPublic() string
- type FileMap
- type FileVal
- type HookContext
- type OnChangeHook
- type ParsedConfig
- func (c *ParsedConfig) CriticalCSSEntry() string
- func (c *ParsedConfig) HealthcheckEndpoint() string
- func (c *ParsedConfig) NonCriticalCSSEntry() string
- func (c *ParsedConfig) PublicPathPrefix() string
- func (c *ParsedConfig) UsingBrowser() bool
- func (c *ParsedConfig) UsingVite() bool
- func (c *ParsedConfig) ViteManifestPath() string
- func (c *ParsedConfig) WatchRoot() string
- type RefreshAction
- type SortedHooks
- type StaticAssetDirs
- type Timing
- type ViteConfig
- type WatchConfig
- type WatchedFile
- type Wave
- func (w *Wave) AddFrameworkWatchPatterns(patterns []WatchedFile)
- func (w *Wave) AddIgnoredPatterns(patterns []string)
- func (w *Wave) FaviconRedirect() middleware.Middleware
- func (w *Wave) GetBaseFS() (fs.FS, error)
- func (w *Wave) GetConfigFile() string
- func (w *Wave) GetCriticalCSS() template.CSS
- func (w *Wave) GetCriticalCSSElementID() string
- func (w *Wave) GetCriticalCSSStyleElement() template.HTML
- func (w *Wave) GetCriticalCSSStyleElementSha256Hash() string
- func (w *Wave) GetDistDir() string
- func (w *Wave) GetIsDev() bool
- func (w *Wave) GetParsedConfig() *ParsedConfig
- func (w *Wave) GetPrivateFS() (fs.FS, error)
- func (w *Wave) GetPrivateStaticDir() string
- func (w *Wave) GetPublicFS() (fs.FS, error)
- func (w *Wave) GetPublicFileMap() (FileMap, error)
- func (w *Wave) GetPublicFileMapElements() template.HTML
- func (w *Wave) GetPublicFileMapScriptSha256Hash() string
- func (w *Wave) GetPublicFileMapURL() string
- func (w *Wave) GetPublicPathPrefix() string
- func (w *Wave) GetPublicStaticDir() string
- func (w *Wave) GetPublicURL(original string) string
- func (w *Wave) GetRefreshScript() template.HTML
- func (w *Wave) GetRefreshScriptSha256Hash() string
- func (w *Wave) GetServeStaticHandler(immutable bool) (http.Handler, error)
- func (w *Wave) GetStaticPrivateOutDir() string
- func (w *Wave) GetStaticPublicOutDir() string
- func (w *Wave) GetStyleSheetElementID() string
- func (w *Wave) GetStyleSheetLinkElement() template.HTML
- func (w *Wave) GetStyleSheetURL() string
- func (w *Wave) GetViteManifestLocation() string
- func (w *Wave) GetViteOutDir() string
- func (w *Wave) IsPublicAsset(urlPath string) bool
- func (w *Wave) Logger() *slog.Logger
- func (w *Wave) MustGetPort() int
- func (w *Wave) MustGetPrivateFS() fs.FS
- func (w *Wave) MustGetPublicFS() fs.FS
- func (w *Wave) MustGetServeStaticHandler(immutable bool) http.Handler
- func (w *Wave) RawConfigJSON() []byte
- func (w *Wave) ServeStatic(immutable bool) func(http.Handler) http.Handler
- func (w *Wave) SetModeToDev()
- func (w *Wave) SetPublicFileMapOutDir(dir string)
Constants ¶
const ( PrehashedDirname = "prehashed" NohashDirname = "__nohash" HashedOutputPrefix = "vorma_out_" HashedOutputPrefixNoTrailing = "vorma_out" NormalCSSBaseName = "vorma_internal_normal.css" NormalCSSGlobPattern = HashedOutputPrefix + "vorma_internal_normal_*.css" GeneratedTSFileName = "index.ts" PublicFileMapTSName = "filemap.ts" PublicFileMapJSONName = "filemap.json" FileMapJSGlobPattern = HashedOutputPrefix + "vorma_internal_public_filemap_*.js" )
Public constants
const ( CriticalCSSElementID = "wave-critical-css" StyleSheetElementID = "wave-normal-css" )
Variables ¶
var MustGetAppPort = MustGetPort
MustGetAppPort is an alias for MustGetPort for backward compatibility.
var RelPaths = relPaths{}
RelPaths provides fs.FS-relative paths (no leading slash, forward slashes).
Functions ¶
func GetRefreshServerPort ¶
func GetRefreshServerPort() int
func MustGetPort ¶
func MustGetPort() int
MustGetPort returns the application port. In dev mode, finds a free port if needed.
func RefreshScriptInner ¶
RefreshScriptInner returns the raw JavaScript for the refresh script. Exported so devserver can serve it via HTTP endpoint.
func SetModeToDev ¶
func SetModeToDev()
func SetRefreshServerPort ¶
func SetRefreshServerPort(port int)
Types ¶
type CSSEntryFiles ¶
type Config ¶
type Config struct {
// Required -- the bytes of your wave.config.json file.
// You can use go:embed or just read the file in yourself.
// Using go:embed is recommended for simpler deployments and improved performance.
WaveConfigJSON []byte
// Required -- be sure to pass in a file system that has your
// <distDir>/static directory as its ROOT.
// If you are using an embedded filesystem, you may need to use fs.Sub to get the
// correct subdirectory.
// Using go:embed is recommended for simpler deployments and improved performance.
DistStaticFS fs.FS
// Optional -- a logger instance.
// If not provided, a default logger will be created that writes to standard out.
Logger *slog.Logger
}
Config configures Wave initialization.
type CoreConfig ¶
type CoreConfig struct {
ConfigLocation string `json:"ConfigLocation,omitempty"`
DevBuildHook string `json:"DevBuildHook,omitempty"`
ProdBuildHook string `json:"ProdBuildHook,omitempty"`
MainAppEntry string `json:"MainAppEntry"`
DistDir string `json:"DistDir"`
StaticAssetDirs StaticAssetDirs `json:"StaticAssetDirs"`
CSSEntryFiles CSSEntryFiles `json:"CSSEntryFiles,omitempty"`
PublicPathPrefix string `json:"PublicPathPrefix,omitempty"`
ServerOnlyMode bool `json:"ServerOnlyMode,omitempty"`
SequentialGoBuild bool `json:"SequentialGoBuild,omitempty"`
}
type DistLayout ¶
type DistLayout struct {
Root string
}
DistLayout provides computed paths for the dist directory structure.
func (DistLayout) Binary ¶
func (d DistLayout) Binary() string
func (DistLayout) CriticalCSS ¶
func (d DistLayout) CriticalCSS() string
func (DistLayout) Internal ¶
func (d DistLayout) Internal() string
func (DistLayout) KeepFile ¶
func (d DistLayout) KeepFile() string
func (DistLayout) NormalCSSRef ¶
func (d DistLayout) NormalCSSRef() string
func (DistLayout) PrivateFileMapGob ¶
func (d DistLayout) PrivateFileMapGob() string
func (DistLayout) PublicFileMapGob ¶
func (d DistLayout) PublicFileMapGob() string
func (DistLayout) PublicFileMapRef ¶
func (d DistLayout) PublicFileMapRef() string
func (DistLayout) Static ¶
func (d DistLayout) Static() string
func (DistLayout) StaticAssets ¶
func (d DistLayout) StaticAssets() string
func (DistLayout) StaticPrivate ¶
func (d DistLayout) StaticPrivate() string
func (DistLayout) StaticPublic ¶
func (d DistLayout) StaticPublic() string
type HookContext ¶
type HookContext struct {
// FilePath is the absolute path of the changed file.
FilePath string
// AppStoppedForBatch is true when the app has been stopped as part of batch
// processing (e.g., a Go file changed in the same batch). When true, HTTP
// endpoints on the running app cannot be called.
AppStoppedForBatch bool
}
HookContext provides context to callbacks during file change handling.
type OnChangeHook ¶
type OnChangeHook struct {
// Cmd is a shell command to run. Can be any shell command or "DevBuildHook"
// to run the configured dev build hook.
Cmd string `json:"Cmd,omitempty"`
// Timing controls when the hook runs relative to Wave's rebuild process.
Timing Timing `json:"Timing,omitempty"`
// Exclude contains glob patterns for files to exclude from triggering this hook.
Exclude []string `json:"Exclude,omitempty"`
// Callback is a Go function to run. Framework use only (not JSON-configurable).
// If the callback returns a non-nil RefreshAction, it controls what Wave does
// after all hooks complete. Multiple RefreshActions are merged with OR semantics.
Callback func(*HookContext) (*RefreshAction, error) `json:"-"`
}
OnChangeHook defines an action to run when a watched file changes.
type ParsedConfig ¶
type ParsedConfig struct {
Core *CoreConfig `json:"Core"`
Vite *ViteConfig `json:"Vite,omitempty"`
Watch *WatchConfig `json:"Watch,omitempty"`
Dist DistLayout `json:"-"`
FrameworkWatchPatterns []WatchedFile `json:"-"`
FrameworkIgnoredPatterns []string `json:"-"`
FrameworkPublicFileMapOutDir string `json:"-"`
FrameworkSchemaExtensions map[string]jsonschema.Entry `json:"-"`
FrameworkDevBuildHook string `json:"-"`
FrameworkProdBuildHook string `json:"-"`
}
ParsedConfig is the parsed and validated wave.config.json
func ParseConfig ¶
func ParseConfig(data []byte) (*ParsedConfig, error)
ParseConfig parses wave.config.json bytes into a ParsedConfig. This performs minimal validation to prevent nil pointer panics during parsing. Full validation of required fields should be done at build time via tooling.ValidateConfig.
func ParseConfigFile ¶
func ParseConfigFile(path string) (*ParsedConfig, error)
ParseConfigFile reads and parses a config file
func (*ParsedConfig) CriticalCSSEntry ¶
func (c *ParsedConfig) CriticalCSSEntry() string
func (*ParsedConfig) HealthcheckEndpoint ¶
func (c *ParsedConfig) HealthcheckEndpoint() string
func (*ParsedConfig) NonCriticalCSSEntry ¶
func (c *ParsedConfig) NonCriticalCSSEntry() string
func (*ParsedConfig) PublicPathPrefix ¶
func (c *ParsedConfig) PublicPathPrefix() string
func (*ParsedConfig) UsingBrowser ¶
func (c *ParsedConfig) UsingBrowser() bool
func (*ParsedConfig) UsingVite ¶
func (c *ParsedConfig) UsingVite() bool
func (*ParsedConfig) ViteManifestPath ¶
func (c *ParsedConfig) ViteManifestPath() string
func (*ParsedConfig) WatchRoot ¶
func (c *ParsedConfig) WatchRoot() string
type RefreshAction ¶
type RefreshAction struct {
// ReloadBrowser triggers a browser reload via WebSocket.
// Ignored if TriggerRestart is true.
ReloadBrowser bool
// WaitForApp polls the app's healthcheck before reloading the browser.
// Ignored if TriggerRestart is true.
WaitForApp bool
// WaitForVite waits for Vite dev server to be ready before reloading.
// Ignored if TriggerRestart is true.
WaitForVite bool
// TriggerRestart causes Wave to restart the app process.
// When true, ReloadBrowser/WaitForApp/WaitForVite are ignored.
TriggerRestart bool
// RecompileGo recompiles the Go binary before restart.
// Only relevant when TriggerRestart is true.
RecompileGo bool
}
RefreshAction specifies what Wave should do after a callback completes. Multiple RefreshActions from different hooks are merged with OR semantics.
func (RefreshAction) IsZero ¶
func (r RefreshAction) IsZero() bool
IsZero returns true if this RefreshAction specifies no action.
func (RefreshAction) Merge ¶
func (r RefreshAction) Merge(other RefreshAction) RefreshAction
Merge combines two RefreshActions with OR semantics. TriggerRestart takes precedence over browser reload.
type SortedHooks ¶
type SortedHooks struct {
Pre []OnChangeHook
Concurrent []OnChangeHook
ConcurrentNoWait []OnChangeHook
Post []OnChangeHook
}
type StaticAssetDirs ¶
type Timing ¶
type Timing string
Timing represents when an OnChangeHook runs relative to Wave's rebuild process
const ( // Blocks build, use when build depends on hook output (e.g., code generation) OnChangeStrategyPre Timing = "pre" // Blocks reload, use when hook depends on build output (e.g., something that reads compiled artifacts) OnChangeStrategyPost Timing = "post" // Runs during build, blocks reload, saves time when hook and build are independent OnChangeStrategyConcurrent Timing = "concurrent" // Fire-and-forget, blocks nothing OnChangeStrategyConcurrentNoWait Timing = "concurrent-no-wait" )
type ViteConfig ¶
type WatchConfig ¶
type WatchConfig struct {
WatchRoot string `json:"WatchRoot,omitempty"`
HealthcheckEndpoint string `json:"HealthcheckEndpoint,omitempty"`
Include []WatchedFile `json:"Include,omitempty"`
Exclude struct {
Dirs []string `json:"Dirs,omitempty"`
Files []string `json:"Files,omitempty"`
} `json:"Exclude,omitempty"`
}
type WatchedFile ¶
type WatchedFile struct {
Pattern string `json:"Pattern"`
OnChangeHooks []OnChangeHook `json:"OnChangeHooks,omitempty"`
RecompileGoBinary bool `json:"RecompileGoBinary,omitempty"`
RestartApp bool `json:"RestartApp,omitempty"`
OnlyRunClientDefinedRevalidateFunc bool `json:"OnlyRunClientDefinedRevalidateFunc,omitempty"`
RunOnChangeOnly bool `json:"RunOnChangeOnly,omitempty"`
SkipRebuildingNotification bool `json:"SkipRebuildingNotification,omitempty"`
TreatAsNonGo bool `json:"TreatAsNonGo,omitempty"`
SortedHooks *SortedHooks `json:"-"`
}
func (*WatchedFile) Sort ¶
func (wf *WatchedFile) Sort()
type Wave ¶
type Wave struct {
// contains filtered or unexported fields
}
Wave provides runtime services for Wave applications.
func (*Wave) AddFrameworkWatchPatterns ¶
func (w *Wave) AddFrameworkWatchPatterns(patterns []WatchedFile)
AddFrameworkWatchPatterns adds watch patterns for use during development.
func (*Wave) AddIgnoredPatterns ¶
AddIgnoredPatterns adds glob patterns for files/directories to ignore during watching.
func (*Wave) FaviconRedirect ¶
func (w *Wave) FaviconRedirect() middleware.Middleware
func (*Wave) GetConfigFile ¶
func (*Wave) GetCriticalCSS ¶
func (*Wave) GetCriticalCSSElementID ¶
func (*Wave) GetCriticalCSSStyleElement ¶
func (*Wave) GetCriticalCSSStyleElementSha256Hash ¶
func (*Wave) GetDistDir ¶
func (*Wave) GetParsedConfig ¶
func (w *Wave) GetParsedConfig() *ParsedConfig
GetParsedConfig returns the parsed configuration for use by tooling. This should only be used by build-time tooling, not at runtime.
func (*Wave) GetPrivateStaticDir ¶
func (*Wave) GetPublicFileMap ¶
func (*Wave) GetPublicFileMapElements ¶
func (*Wave) GetPublicFileMapScriptSha256Hash ¶
func (*Wave) GetPublicFileMapURL ¶
func (*Wave) GetPublicPathPrefix ¶
func (*Wave) GetPublicStaticDir ¶
func (*Wave) GetPublicURL ¶
func (*Wave) GetRefreshScript ¶
func (*Wave) GetRefreshScriptSha256Hash ¶
func (*Wave) GetServeStaticHandler ¶
func (*Wave) GetStaticPrivateOutDir ¶
func (*Wave) GetStaticPublicOutDir ¶
func (*Wave) GetStyleSheetElementID ¶
func (*Wave) GetStyleSheetLinkElement ¶
func (*Wave) GetStyleSheetURL ¶
func (*Wave) GetViteManifestLocation ¶
func (*Wave) GetViteOutDir ¶
func (*Wave) IsPublicAsset ¶
func (*Wave) MustGetPort ¶
MustGetPort returns the application port.
func (*Wave) MustGetPrivateFS ¶
func (*Wave) MustGetPublicFS ¶
func (*Wave) MustGetServeStaticHandler ¶
func (*Wave) RawConfigJSON ¶
RawConfigJSON returns the raw bytes of the configuration file.
func (*Wave) ServeStatic ¶
func (*Wave) SetModeToDev ¶
func (w *Wave) SetModeToDev()
SetModeToDev sets the environment to development mode.
func (*Wave) SetPublicFileMapOutDir ¶
SetPublicFileMapOutDir sets the directory where Wave should write the public filemap TypeScript file.