config

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package config provides configuration parsing for Vango projects.

The configuration is stored in vango.json at the project root. This package handles loading, saving, and validating configuration.

Configuration File Structure

{
  "dev": {
    "port": 8000,
    "appPort": 8888,
    "host": "localhost",
    "openBrowser": true,
    "https": false,
    "proxy": {
      "/api/external": "https://api.example.com"
    }
  },
  "build": {
    "output": "dist",
    "minify": true,
    "sourceMaps": false
  },
  "tailwind": {
    "enabled": true,
    "config": "./tailwind.config.js"
  },
  "ui": {
    "version": "1.0.0",
    "registry": "https://vango.dev/registry.json",
    "installed": ["button", "card"]
  },
  "hooks": "./public/js/hooks.js"
}

Usage

cfg, err := config.Load(".")
if err != nil {
    log.Fatal(err)
}

fmt.Println("Port:", cfg.Dev.Port)

Index

Constants

View Source
const (
	// ConfigFileName is the name of the configuration file.
	ConfigFileName = "vango.json"

	// DefaultPort is the default development server port.
	DefaultPort = 8000

	// DefaultAppPort is the default backend app process port in dev mode.
	DefaultAppPort = 8888

	// DefaultHost is the default development server host.
	DefaultHost = "localhost"

	// DefaultOutput is the default build output directory.
	DefaultOutput = "dist"

	// DefaultRegistry is the default component registry URL.
	DefaultRegistry = "https://vango.dev/registry.json"
)
View Source
const (
	EnvSessionStoreURL           = "VANGO_SESSION_STORE_URL"
	EnvPubSubURL                 = "VANGO_PUBSUB_URL"
	EnvBlobsURL                  = "VANGO_BLOBS_URL"
	EnvCacheURL                  = "VANGO_CACHE_URL"
	EnvPersistenceSecret         = "VANGO_PERSISTENCE_SECRET"
	EnvPersistenceSecretPrevious = "VANGO_PERSISTENCE_SECRET_PREVIOUS"
	EnvPlatformSealed            = "VANGO_PLATFORM_SEALED"
	EnvEnvironment               = "VANGO_ENV"
	EnvStrict                    = "VANGO_STRICT"
)

Variables

This section is empty.

Functions

func Exists

func Exists(dir string) bool

Exists checks if a config file exists in the given directory.

func FindProjectRoot

func FindProjectRoot(startDir string) (string, error)

FindProjectRoot walks up directories to find the project root. Returns the directory containing vango.json, or an error if not found.

func LoadFromEnv

func LoadFromEnv(cfg *SessionConfig)

LoadFromEnv populates session config from environment variables. Invalid values are ignored to keep startup non-fatal.

func ParseSessionStoreURL

func ParseSessionStoreURL(raw string) (session.SessionStore, error)

ParseSessionStoreURL creates a SessionStore from a URL.

Types

type BuildConfig

type BuildConfig struct {
	// Output is the output directory for builds.
	Output string `json:"output,omitempty"`

	// Minify enables minification.
	Minify bool `json:"minify,omitempty"`

	// MinifyAssets enables minification of CSS and JS assets.
	MinifyAssets bool `json:"minifyAssets,omitempty"`

	// StripSymbols strips debug symbols from the binary (-ldflags="-s -w").
	StripSymbols bool `json:"stripSymbols,omitempty"`

	// SourceMaps enables source map generation.
	SourceMaps bool `json:"sourceMaps,omitempty"`

	// Target is the Go build target (e.g., "linux/amd64").
	Target string `json:"target,omitempty"`

	// LDFlags are additional linker flags for go build.
	LDFlags string `json:"ldflags,omitempty"`

	// Tags are build tags to pass to go build.
	Tags []string `json:"tags,omitempty"`

	// GeneratorInputs are inputs that affect generated code and build schema.
	GeneratorInputs []string `json:"generatorInputs,omitempty"`
}

BuildConfig contains production build settings.

type Config

type Config struct {
	// Module is the Go module path (must match go.mod).
	Module string `json:"module,omitempty"`

	// Name is the project name.
	Name string `json:"name,omitempty"`

	// Version is the project version.
	Version string `json:"version,omitempty"`

	// Strict controls lint strict mode (default, ci).
	Strict string `json:"strict,omitempty"`

	// Platform contains platform-specific configuration.
	Platform PlatformConfig `json:"platform,omitempty"`

	// Port is the default server port (convenience field, also in Dev).
	Port int `json:"port,omitempty"`

	// Routes configures file-based routing generation.
	Routes RoutesConfig `json:"routes,omitempty"`

	// Paths contains path configuration for various directories.
	Paths PathsConfig `json:"paths,omitempty"`

	// Static contains static file serving configuration.
	Static StaticConfig `json:"static,omitempty"`

	// Dev contains development server configuration.
	Dev DevConfig `json:"dev,omitempty"`

	// Build contains production build configuration.
	Build BuildConfig `json:"build,omitempty"`

	// Tailwind contains Tailwind CSS configuration.
	Tailwind TailwindConfig `json:"tailwind,omitempty"`

	// Session contains session configuration.
	Session SessionConfig `json:"session,omitempty"`

	// UI contains VangoUI component configuration (legacy, use Paths.UI).
	UI UIConfig `json:"ui,omitempty"`

	// Hooks is the path to custom client hooks JavaScript file.
	Hooks string `json:"hooks,omitempty"`

	// Components is the path to the components directory (legacy, use Paths.Components).
	Components string `json:"components,omitempty"`

	// Public is the path to the public static files directory (legacy, use Static.Dir).
	Public string `json:"public,omitempty"`
	// contains filtered or unexported fields
}

Config represents the complete vango.json configuration. This is aligned with the v1 schema in DEVELOPER_GUIDE.md Appendix C.

func Load

func Load(dir string) (*Config, error)

Load reads configuration from the specified directory. It looks for vango.json in the directory.

func LoadFile

func LoadFile(path string) (*Config, error)

LoadFile reads configuration from the specified file path.

func LoadFromWorkingDir

func LoadFromWorkingDir() (*Config, error)

LoadFromWorkingDir loads configuration from the current working directory.

func New

func New() *Config

New creates a new Config with default values.

func (*Config) ComponentsPath

func (c *Config) ComponentsPath() string

ComponentsPath returns the absolute path to the components directory.

func (*Config) DevAddress

func (c *Config) DevAddress() string

DevAddress returns the address string for the dev server.

func (*Config) DevURL

func (c *Config) DevURL() string

DevURL returns the full URL for the dev server.

func (*Config) Dir

func (c *Config) Dir() string

Dir returns the directory containing the config file.

func (*Config) HasTailwind

func (c *Config) HasTailwind() bool

HasTailwind returns true if Tailwind CSS is enabled.

func (*Config) IsPlatformSealed

func (c *Config) IsPlatformSealed() bool

IsPlatformSealed returns true when platform config is sealed.

func (*Config) IsStrictCI

func (c *Config) IsStrictCI() bool

IsStrictCI returns true when strict mode is set to CI.

func (*Config) MiddlewarePath

func (c *Config) MiddlewarePath() string

MiddlewarePath returns the absolute path to the middleware directory.

func (*Config) OutputPath

func (c *Config) OutputPath() string

OutputPath returns the absolute path to the build output directory.

func (*Config) Path

func (c *Config) Path() string

Path returns the path where the config was loaded from.

func (*Config) PublicPath

func (c *Config) PublicPath() string

PublicPath returns the absolute path to the public directory.

func (*Config) RoutesOutputPath

func (c *Config) RoutesOutputPath() string

RoutesOutputPath returns the absolute path to the generated routes file.

func (*Config) RoutesPath

func (c *Config) RoutesPath() string

RoutesPath returns the absolute path to the routes directory.

func (*Config) Save

func (c *Config) Save() error

Save writes the configuration to the file it was loaded from.

func (*Config) SaveTo

func (c *Config) SaveTo(path string) error

SaveTo writes the configuration to the specified path.

func (*Config) StaticPrefix

func (c *Config) StaticPrefix() string

StaticPrefix returns the URL prefix for static files.

func (*Config) StorePath

func (c *Config) StorePath() string

StorePath returns the absolute path to the store directory.

func (*Config) StrictMode

func (c *Config) StrictMode() string

StrictMode returns the effective strict mode (env overrides config).

func (*Config) TailwindConfigPath

func (c *Config) TailwindConfigPath() string

TailwindConfigPath returns the absolute path to the Tailwind config.

func (*Config) UIComponentsPath

func (c *Config) UIComponentsPath() string

UIComponentsPath returns the absolute path to the UI components directory.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if the configuration is valid.

type DevConfig

type DevConfig struct {
	// Port is the port to run the dev server on.
	Port int `json:"port,omitempty"`

	// AppPort is the backend application process port used by the dev proxy.
	AppPort int `json:"appPort,omitempty"`

	// Host is the host to bind to.
	Host string `json:"host,omitempty"`

	// OpenBrowser opens the browser automatically on start.
	OpenBrowser bool `json:"openBrowser,omitempty"`

	// HTTPS enables HTTPS for the dev server.
	HTTPS bool `json:"https,omitempty"`

	// Proxy contains proxy rules for forwarding requests.
	Proxy map[string]string `json:"proxy,omitempty"`

	// Watch contains paths to watch for changes.
	Watch []string `json:"watch,omitempty"`

	// Ignore contains patterns to ignore during watch.
	Ignore []string `json:"ignore,omitempty"`

	// HotReload enables hot reload in development.
	HotReload bool `json:"hotReload,omitempty"`
}

DevConfig contains development server settings.

type PathsConfig

type PathsConfig struct {
	// Components is the path to the components directory.
	Components string `json:"components,omitempty"`

	// UI is the path to the UI components directory.
	UI string `json:"ui,omitempty"`

	// Store is the path to the store directory.
	Store string `json:"store,omitempty"`

	// Middleware is the path to the middleware directory.
	Middleware string `json:"middleware,omitempty"`
}

PathsConfig contains path configuration for project directories.

type PlatformConfig

type PlatformConfig struct {
	// Sealed prevents app config from overriding platform settings.
	Sealed bool `json:"sealed,omitempty"`

	// Name is the platform identifier (for logging/display).
	Name string `json:"name,omitempty"`
}

PlatformConfig contains platform-specific settings.

type RoutesConfig

type RoutesConfig struct {
	// Dir is the path to the routes directory.
	Dir string `json:"dir,omitempty"`

	// Output is the output file path for generated routes glue.
	Output string `json:"output,omitempty"`

	// Package is the Go package name for generated routes glue.
	Package string `json:"package,omitempty"`
}

RoutesConfig contains file-based routing configuration.

type RuntimePlatform

type RuntimePlatform struct {
	// SessionStoreURL is the session persistence backend URL.
	SessionStoreURL string

	// PubSubURL is the broadcast/pubsub backend URL.
	PubSubURL string

	// BlobsURL is the blob storage backend URL.
	BlobsURL string

	// CacheURL is the cache backend URL.
	CacheURL string

	// PersistenceSecret is the HMAC secret for persistence blobs.
	PersistenceSecret string

	// PersistenceSecretPrevious is the previous HMAC secret for rotation.
	PersistenceSecretPrevious string

	// Environment is the runtime environment (dev/staging/production).
	Environment string

	// Name is the platform identifier (optional).
	Name string

	// Sealed prevents app overrides.
	Sealed bool
}

RuntimePlatform contains resolved platform configuration.

func ResolvePlatform

func ResolvePlatform(cfg *Config) *RuntimePlatform

ResolvePlatform resolves platform configuration from config and environment.

func (*RuntimePlatform) HasBroadcast

func (rp *RuntimePlatform) HasBroadcast() bool

HasBroadcast returns true if a pubsub backend is configured.

func (*RuntimePlatform) HasPersistence

func (rp *RuntimePlatform) HasPersistence() bool

HasPersistence returns true if a session store is configured.

type SessionConfig

type SessionConfig struct {
	// ResumeWindow is the duration for session resumption (e.g., "30s").
	ResumeWindow string `json:"resumeWindow,omitempty"`

	// Store is the session persistence backend (env-only).
	Store session.SessionStore `json:"-"`

	// PersistenceSecret signs persisted session blobs (env-only).
	PersistenceSecret []byte `json:"-"`

	// PersistenceSecretPrevious allows secret rotation (env-only).
	PersistenceSecretPrevious []byte `json:"-"`
}

SessionConfig contains session configuration.

type StaticConfig

type StaticConfig struct {
	// Dir is the directory containing static files.
	Dir string `json:"dir,omitempty"`

	// Prefix is the URL prefix for static files (default: "/").
	Prefix string `json:"prefix,omitempty"`
}

StaticConfig contains static file serving configuration.

type TailwindConfig

type TailwindConfig struct {
	// Enabled controls whether Tailwind CSS is used.
	Enabled bool `json:"enabled,omitempty"`

	// Config is the path to tailwind.config.js.
	Config string `json:"config,omitempty"`

	// Input is the input CSS file.
	Input string `json:"input,omitempty"`

	// Output is the output CSS file.
	Output string `json:"output,omitempty"`
}

TailwindConfig contains Tailwind CSS settings.

type UIConfig

type UIConfig struct {
	// Version is the pinned VangoUI version.
	Version string `json:"version,omitempty"`

	// Registry is the URL to the component registry.
	Registry string `json:"registry,omitempty"`

	// Installed is the list of installed components.
	Installed []string `json:"installed,omitempty"`

	// Path is the path where UI components are stored.
	Path string `json:"path,omitempty"`
}

UIConfig contains VangoUI component settings.

Jump to

Keyboard shortcuts

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