waveenv

package
v0.85.0-pre.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2026 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package waveenv provides runtime-safe environment and path primitives used by Wave runtime and config parsing.

This package intentionally excludes build/dev-only helpers (for example lock management and glob utilities) so importing wave runtime APIs does not pull those heavier dependencies into runtime binaries.

Index

Constants

View Source
const (
	// EnvMode stores the current Wave runtime mode.
	EnvMode = "__WAVE_MODE"
	// EnvModeDev is the development-mode value for EnvMode.
	EnvModeDev = "development"
	// EnvPort is the application runtime port environment variable.
	EnvPort = "PORT"
	// EnvPortSet marks that Wave has already resolved and set EnvPort in this
	// process.
	EnvPortSet = "__WAVE_PORT_HAS_BEEN_SET"
	// EnvRefreshServerPort stores the dev refresh websocket server port.
	EnvRefreshServerPort = "__WAVE_REFRESH_SERVER_PORT"
)

Variables

This section is empty.

Functions

func Absolute

func Absolute(path string) string

Absolute resolves one path to an absolute cleaned form.

func AbsoluteDirectory

func AbsoluteDirectory(path string) string

AbsoluteDirectory resolves an input path to an absolute directory path.

func AbsoluteSlash

func AbsoluteSlash(path string) string

AbsoluteSlash resolves one absolute path and normalizes separators to '/'.

func CanonicalizePathForLocationComparison

func CanonicalizePathForLocationComparison(path string) string

CanonicalizePathForLocationComparison resolves one path for location equality checks.

func GetIsDev

func GetIsDev() bool

GetIsDev reports whether EnvMode is currently set to development.

func IsMachineAbsoluteFilesystemPath

func IsMachineAbsoluteFilesystemPath(pathForCheck string) bool

IsMachineAbsoluteFilesystemPath reports whether a path is machine-absolute.

This treats both OS-native absolute paths and slash-rooted strings (for example "/dist") as machine-absolute filesystem paths.

func ParseEnvPort

func ParseEnvPort() int

ParseEnvPort parses EnvPort and returns 0 when unset or invalid.

func ParseRefreshServerPort

func ParseRefreshServerPort() int

ParseRefreshServerPort parses EnvRefreshServerPort and returns 0 when unset or invalid.

func PathsReferToSameLocation

func PathsReferToSameLocation(pathA string, pathB string) bool

PathsReferToSameLocation reports whether both paths normalize to the same location.

func ResolveFromReferencedPath

func ResolveFromReferencedPath(
	publicPathPrefix string,
	referencedPath string,
) string

ResolveFromReferencedPath resolves a referenced asset path under publicPathPrefix. It trims, normalizes, and rejects empty/effectively-empty referenced paths.

func SetEnvPort

func SetEnvPort(port int)

SetEnvPort writes the runtime port into EnvPort.

func SetModeToDev

func SetModeToDev()

SetModeToDev marks EnvMode as development.

func SetRefreshServerPort

func SetRefreshServerPort(port int)

SetRefreshServerPort writes one refresh websocket port value into env.

func TrimAndCleanPath

func TrimAndCleanPath(path string) string

TrimAndCleanPath trims surrounding whitespace and applies filepath.Clean.

Types

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver caches resolved runtime port values for a given mode view.

func NewResolver

func NewResolver() *Resolver

NewResolver constructs a resolver that reads mode dynamically from env.

func NewResolverForMode

func NewResolverForMode(isDev bool) *Resolver

NewResolverForMode constructs a resolver pinned to an explicit mode snapshot.

func NewResolverWithFreePortResolver

func NewResolverWithFreePortResolver(
	getFreePort func(int) (int, error),
) *Resolver

NewResolverWithFreePortResolver constructs a resolver with one injected free-port lookup function. This is primarily used when callers need deterministic behavior.

func (*Resolver) MustGetPort

func (resolver *Resolver) MustGetPort() int

MustGetPort returns the runtime port. In dev mode, empty PORT uses framework default base-port selection. It panics in dev mode when PORT is invalid or a free port cannot be resolved. It panics in non-dev mode when PORT is missing or invalid.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL