dev

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package dev runs a web service's local development dependencies without Docker, and is the base for an app's own development command.

Index

Constants

View Source
const ConfigFile = "dev.json"

ConfigFile is the name the dev command looks for, from the working directory up, so that `go -C tools tool dev` still finds the repository's.

Variables

This section is empty.

Functions

func FindConfig

func FindConfig(dir string) (string, error)

FindConfig returns the path of the nearest dev.json in dir or its parents.

func NewRootCmd

func NewRootCmd(cfg Config) *cobra.Command

NewRootCmd returns the dev command with the standard subcommands. An app with its own development tasks adds them with AddCommand.

func ResetStack

func ResetStack(ctx context.Context, cfg Config, logger *slog.Logger) error

ResetStack deletes the stack's data. A server still running from the same directory is stopped first, since it would recreate files as they go.

func WaitStack

func WaitStack(ctx context.Context, cfg Config, timeout time.Duration) error

WaitStack blocks until a stack started elsewhere accepts connections, so that a server started alongside it does not race it.

Types

type Config

type Config struct {
	// Name is the Postgres user, password and database. Tests get Name_test.
	Name string `json:"name"`
	// Dir keeps Postgres data and S3 objects between runs. Relative to the
	// config file when loaded from one; defaults to .devstack.
	Dir string `json:"dir,omitempty"`
	// Postgres runs when set.
	Postgres *Postgres `json:"postgres,omitempty"`
	// S3 runs when set.
	S3 *S3 `json:"s3,omitempty"`
}

Config describes an app's local stack.

func LoadConfig

func LoadConfig(path string) (Config, error)

LoadConfig reads a dev.json and resolves Dir against its directory.

func (Config) DatabaseURL

func (c Config) DatabaseURL() string

DatabaseURL is the URL of the app's database, or "" without Postgres.

func (Config) TestDatabaseURL

func (c Config) TestDatabaseURL() string

TestDatabaseURL is the URL of the database for tests, or "" without Postgres.

type Postgres

type Postgres struct {
	// Port defaults to 5432.
	Port int `json:"port,omitempty"`
	// Parameters are server settings, e.g. max_connections for test suites
	// that open pools in parallel.
	Parameters map[string]string `json:"parameters,omitempty"`
}

Postgres configures the local PostgreSQL server.

type S3

type S3 struct {
	// Addr defaults to 127.0.0.1:8333.
	Addr string `json:"addr,omitempty"`
}

S3 configures the local S3-compatible server.

type Stack

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

Stack is a running set of local dependencies.

func StartStack

func StartStack(ctx context.Context, cfg Config, logger *slog.Logger) (*Stack, error)

StartStack starts the configured dependencies and returns once they accept connections. The first run downloads the Postgres binaries.

func (*Stack) Stop

func (s *Stack) Stop(ctx context.Context) error

Stop shuts the dependencies down; Postgres flushes its data first.

Directories

Path Synopsis
cmd
dev command
Command dev runs an app's local development stack as described by the nearest dev.json.
Command dev runs an app's local development stack as described by the nearest dev.json.

Jump to

Keyboard shortcuts

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