app

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package app contains the business logic for the gow CLI, separated from the cobra command wiring in cmd/gow. All side-effecting operations are injected via the Deps struct, making every operation testable without real hardware, filesystem, or network access.

Index

Constants

This section is empty.

Variables

View Source
var (
	StackOpInstall = stackOp{
					// contains filtered or unexported fields
	}
	StackOpUpgrade = stackOp{
					// contains filtered or unexported fields
	}
	StackOpRemove = stackOp{
					// contains filtered or unexported fields
	}
	StackOpPurge = stackOp{
					// contains filtered or unexported fields
	}
	StackOpStart = stackOp{
					// contains filtered or unexported fields
	}
	StackOpStop = stackOp{
				// contains filtered or unexported fields
	}
	StackOpRestart = stackOp{
					// contains filtered or unexported fields
	}
	StackOpReload = stackOp{
					// contains filtered or unexported fields
	}
)

StackOp* declare the supported stack lifecycle operations the CLI can run.

Functions

func AddStackFlags

func AddStackFlags(cmd *cobra.Command, sf *StackFlags)

AddStackFlags registers stack component flags on a cobra command.

func NewManager

func NewManager(cfg CLIConfig, d Deps) (*site.Manager, error)

NewManager constructs a site.Manager using the injected dependencies.

func RunBackup

func RunBackup(cfg CLIConfig, domain string, d Deps) error

RunBackup validates the domain, creates a Manager, and calls Backup.

func RunBackupCron

func RunBackupCron(cfg CLIConfig, d Deps) error

RunBackupCron is the entry point for the hidden backup-cron command. It iterates all sites with a backup schedule, runs backups, and prunes.

func RunBackupSchedule

func RunBackupSchedule(cfg CLIConfig, domain, schedule string, retain int, d Deps) error

RunBackupSchedule sets or updates the automatic backup schedule for a site.

func RunBackupUnschedule

func RunBackupUnschedule(cfg CLIConfig, domain string, d Deps) error

RunBackupUnschedule removes the automatic backup schedule for a site.

func RunClone

func RunClone(cfg CLIConfig, src, dst string, d Deps) error

RunClone validates inputs, creates a Manager, and calls Clone.

func RunCreate

func RunCreate(cfg CLIConfig, sf SiteFlags, domain string, d Deps) error

RunCreate creates a new site.

func RunDelete

func RunDelete(cfg CLIConfig, sf SiteFlags, domain string, d Deps) error

RunDelete deletes a site.

func RunFlush

func RunFlush(cfg CLIConfig, domain string, d Deps) error

RunFlush purges a site's caches via Manager.Flush.

func RunInfo

func RunInfo(cfg CLIConfig, sf SiteFlags, domain string, w io.Writer, d Deps) error

RunInfo shows details for a site.

func RunList

func RunList(cfg CLIConfig, w io.Writer, d Deps) error

RunList lists all managed sites.

func RunLog

func RunLog(cfg CLIConfig, lf LogFlags, domain string, d Deps) error

RunLog tails the site's log file to stdout/stderr.

func RunMetrics

func RunMetrics(cfg CLIConfig, w io.Writer, d Deps, jsonOutput bool) error

RunMetrics collects and displays live server metrics.

func RunOffline

func RunOffline(cfg CLIConfig, domain string, d Deps) error

RunOffline puts a site into maintenance mode.

func RunOnline

func RunOnline(cfg CLIConfig, domain string, d Deps) error

RunOnline brings a site online.

func RunPresets

func RunPresets(w io.Writer) error

RunPresets lists available resource presets.

func RunReconcile

func RunReconcile(cfg CLIConfig, d Deps) error

RunReconcile recomputes allocations and reloads OLS.

func RunRestore

func RunRestore(cfg CLIConfig, domain, archivePath string, d Deps) error

RunRestore validates inputs, creates a Manager, and calls Restore.

func RunSSL

func RunSSL(cfg CLIConfig, sf SiteFlags, domain string, d Deps) error

RunSSL enables SSL for a site.

func RunStackMigrate

func RunStackMigrate(sf StackFlags, d Deps) error

RunStackMigrate migrates a stack component (e.g. MariaDB) to a new version.

func RunStackOp

func RunStackOp(sf StackFlags, op stackOp, d Deps) error

RunStackOp executes a stack operation (install, upgrade, remove, etc.).

func RunStackPurge

func RunStackPurge(cfg CLIConfig, sf StackFlags, d Deps) error

RunStackPurge purges stack packages and configs, blocking if sites depend on them.

func RunStackStatus

func RunStackStatus(w io.Writer, d Deps) error

RunStackStatus shows status for all installed stack components.

func RunStatus

func RunStatus(cfg CLIConfig, w io.Writer, d Deps) error

RunStatus shows current allocations and resource headroom.

func RunUpdate

func RunUpdate(cfg CLIConfig, sf SiteFlags, domain string, d Deps) error

RunUpdate updates a site's PHP version or tuning.

func RunWP

func RunWP(cfg CLIConfig, domain string, args []string, d Deps) error

RunWP passes arguments through to wp-cli scoped to a site's document root.

func ValidateDomain

func ValidateDomain(s string) error

ValidateDomain rejects inputs that cannot safely be used as a site name. The string becomes a system user name, database name, filesystem path component, and OLS config identifier — anything containing shell meta, path separators, SQL meta, or whitespace is rejected here so downstream code can assume clean input.

Types

type CLIConfig

type CLIConfig struct {
	ConfDir    string
	StateFile  string
	PolicyFile string
	WebRoot    string
	LogDir     string // per-site log directory (default: /var/log/lsws)
}

CLIConfig holds paths and flags resolved from the CLI.

type Deps

type Deps struct {
	Ctx          context.Context
	Stdin        io.Reader
	Stdout       io.Writer
	Stderr       io.Writer
	DetectSpecs  func() (system.Specs, error)
	LoadPolicy   func(string) (allocator.Policy, error)
	OpenStore    func(string) (*state.Store, error)
	NewOLS       func() ols.Controller
	NewRunner    func() stack.Runner
	InstalledPHP func() []string
	PHPAvailable func(string) bool
	WPInstall    func(domain, webRoot, cacheMode, multisite string) error
	DBCleanup    func(domain string) error
}

Deps groups the side-effecting operations that app depends on. Production code uses DefaultDeps; tests inject mocks via this struct.

func DefaultDeps

func DefaultDeps() Deps

DefaultDeps returns a Deps struct wired to production implementations.

type LogFlags

type LogFlags struct {
	Access bool // --access
	Error  bool // --error
	Follow bool // --follow / -f
	Lines  int  // --lines / -n
}

LogFlags holds flags for the `site log` command.

type SiteFlags

type SiteFlags struct {
	SiteType       string // --type (create only: html, php, wp)
	PHP            string // --php (version string)
	Preset         string // --tune (blog, woocommerce, custom)
	PHPMemory      uint   // --php-memory
	WorkerBudget   uint   // --worker-budget
	NoCache        bool   // --no-cache (create only, wp only: disable LSCache)
	Multisite      string // --multisite (create only, wp only: subdirectory or subdomain)
	Verbose        bool   // --verbose (info only)
	NoPrompt       bool   // --no-prompt (delete only)
	Isolate        bool   // --isolate (update only)
	SSLEmail       string // --email (ssl only)
	SSLStaging     bool   // --staging (ssl only)
	SSLWildcard    bool   // --wildcard (ssl only, requires --dns)
	SSLDNS         string // --dns (ssl only, currently: "cloudflare")
	SSLHSTS        bool   // --hsts (ssl only)
	RestoreFile    string // --file (restore only)
	BackupSchedule string // --schedule (backup-schedule: daily or weekly)
	BackupRetain   int    // --retain (backup-schedule: number of backups to keep)
}

SiteFlags holds per-command flags for site operations.

type StackFlags

type StackFlags struct {
	OLS      bool
	PHP      string // --php (version string, e.g. "83", "84")
	PHP81    bool
	PHP82    bool
	PHP83    bool
	PHP84    bool
	PHP85    bool
	MariaDB  bool
	Redis    bool
	WPCLI    bool
	Composer bool
	Certbot  bool
	Target   string // --target for migrate
}

StackFlags holds per-command flags for stack operations.

Jump to

Keyboard shortcuts

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