Help us shape the future of Go! Take the 2026 Go Developer Survey

config

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package config owns persisted settings, separate from private runtime credentials.

Index

Constants

View Source
const DefaultConsolePort = 7970

DefaultConsolePort keeps diffx-console beside diffx-server (7980) and off the local `diffx [PATH]` range (7981-7990).

View Source
const DefaultInternalPort = 7979

DefaultInternalPort serves the GitHub fetcher protocol; never publish it.

View Source
const DefaultServerPort = 7980

DefaultServerPort keeps diffx-server off the local `diffx [PATH]` range (7981-7990) so both modes can run on one machine.

Variables

View Source
var Keys = []string{"local.host", "local.port", "local.state", "local.webDir", "local.retentionDays", "remote.url", "remote.token"}

Keys lists persisted settings by dotted path.

Functions

func DefaultStatePath added in v0.2.1

func DefaultStatePath() (string, error)

DefaultStatePath is the local persistent database used when none is configured.

func Edit

func Edit(key string, value *string) error

func EditFile

func EditFile(path, key string, value *string) error

EditFile edits only persisted values, independent of environment overrides. A nil value restores the default.

func Path

func Path() (string, error)

func StateDir added in v0.2.1

func StateDir() (string, error)

StateDir is the private root for the default database, manual sync outboxes and hook state. DIFFX_RUNTIME_DIR isolates all of them with the config file.

Types

type ConsoleValues added in v0.2.4

type ConsoleValues struct {
	Host string
	Port int
	// DatabaseURL is the server's Postgres connection string; never echoed.
	DatabaseURL string
	// PublicURL is the console's browser-facing origin; AppURL is the app's,
	// used in invite and member reset links.
	PublicURL       string
	AppURL          string
	InsecureCookies bool
	// Google is the console's own OAuth client, with its callback on PublicURL.
	Google         Google
	AuthRateLimit  bool
	ClientIPHeader string
}

ConsoleValues configures diffx-console, the admin console over the server's database. It comes only from DIFFX_CONSOLE_* environment variables.

func LoadConsole added in v0.2.4

func LoadConsole() (ConsoleValues, error)

LoadConsole resolves defaults, then the environment.

func (ConsoleValues) ListenAddress added in v0.2.4

func (values ConsoleValues) ListenAddress() (string, error)

func (ConsoleValues) Validate added in v0.2.4

func (values ConsoleValues) Validate() error

Validate checks everything Run needs: the app origin for invite and reset links, the optional console origin, complete Google sign-in and rate limiting.

func (ConsoleValues) ValidateDatabase added in v0.2.4

func (values ConsoleValues) ValidateDatabase() error

ValidateDatabase requires the Postgres connection string without echoing it.

type FetcherValues added in v0.2.1

type FetcherValues struct {
	ServerURL      string
	Secret         string
	Mirrors        string
	DiskLimitBytes int64
	Concurrency    int
}

FetcherValues configures diffx-fetcher. DiskLimitBytes bounds its mirrors.

func LoadFetcher added in v0.2.1

func LoadFetcher() (FetcherValues, error)

LoadFetcher reads DIFFX_FETCHER_* environment only; the fetcher has no config file. Diagnostics never echo the secret.

type GitHub added in v0.2.1

type GitHub struct {
	AppID          int64  `json:"appId"`
	ClientID       string `json:"clientId"`
	PrivateKeyFile string `json:"privateKeyFile"`
	PublicURL      string `json:"publicUrl"`
	ClientSecret   string `json:"-"`
	WebhookSecret  string `json:"-"`
	TokenKey       string `json:"-"`
	// FetcherSecret authenticates diffx-fetcher on the internal listener.
	FetcherSecret string `json:"-"`
}

GitHub configures the optional GitHub App integration. Secrets come only from DIFFX_SERVER_GITHUB_* environment variables, never the config file.

func (GitHub) Enabled added in v0.2.1

func (github GitHub) Enabled() bool

Enabled reports whether any GitHub setting is present; Validate requires all.

func (GitHub) Validate added in v0.2.1

func (github GitHub) Validate(insecureCookies bool) error

Validate requires the complete integration or none of it. publicUrl is the browser-facing origin for OAuth callbacks; plain HTTP is development only.

type Google added in v0.2.2

type Google struct {
	ClientID     string `json:"clientId"`
	ClientSecret string `json:"-"`
}

Google configures Google sign-in. The secret comes only from DIFFX_SERVER_GOOGLE_CLIENT_SECRET, never the config file.

func (Google) Enabled added in v0.2.2

func (google Google) Enabled() bool

Enabled reports whether any Google setting is present; Validate requires all.

type LocalValues added in v0.2.1

type LocalValues struct {
	Host          string `json:"host"`
	Port          *int   `json:"port"`
	State         string `json:"state"`
	WebDir        string `json:"webDir"`
	RetentionDays int    `json:"retentionDays"`
}

LocalValues configure the foreground `diffx [PATH]` server only.

type RemoteValues

type RemoteValues struct {
	URL   string `json:"url"`
	Token string `json:"token"`
}

RemoteValues select the destination for sync and agent hooks only.

type ServerSettings

type ServerSettings struct {
	Host          string `json:"host"`
	Port          int    `json:"port"`
	State         string `json:"state"`
	WebDir        string `json:"webDir"`
	RetentionDays int    `json:"retentionDays"`
}

type ServerValues added in v0.2.1

type ServerValues struct {
	Host string `json:"host"`
	Port int    `json:"port"`
	// DatabaseURL is the Postgres connection string. It holds credentials, so it
	// comes only from DIFFX_SERVER_DATABASE_URL, never a file or flag, and is never echoed.
	DatabaseURL     string `json:"-"`
	PublicURL       string `json:"publicUrl"`
	InsecureCookies bool   `json:"insecureCookies"`
	RetentionDays   int    `json:"retentionDays"`
	// InternalPort listens beside Port, on the same host, when GitHub is enabled.
	InternalPort int    `json:"internalPort"`
	GitHub       GitHub `json:"github"`
	Google       Google `json:"google"`
	// AuthRateLimit bounds authentication attempts per client IP across
	// replicas. The IP comes from ClientIPHeader, which a trusted ingress must
	// set; both come only from the environment.
	AuthRateLimit  bool   `json:"-"`
	ClientIPHeader string `json:"-"`
}

ServerValues is deployment configuration, independent of personal CLI settings.

func LoadServerFile added in v0.2.1

func LoadServerFile(path string) (ServerValues, error)

LoadServerFile resolves defaults, an explicitly selected file, then environment. It never discovers personal config, creates files, or acquires a config lock. Variables use the DIFFX_SERVER_ prefix so they never configure the local CLI.

func (ServerValues) InternalAddress added in v0.2.1

func (values ServerValues) InternalAddress(listen string) (string, error)

InternalAddress places the internal listener on the public listener's host.

func (ServerValues) ListenAddress added in v0.2.1

func (values ServerValues) ListenAddress() (string, error)

ListenAddress validates the configured listener when no flag overrides it.

func (ServerValues) ValidateAuthRateLimit added in v0.2.2

func (values ServerValues) ValidateAuthRateLimit() error

ValidateAuthRateLimit requires a header name when limiting is enabled; the server cannot tell a client from its ingress without one.

func (ServerValues) ValidateDatabase added in v0.2.2

func (values ServerValues) ValidateDatabase() error

ValidateDatabase requires the Postgres connection string without echoing it.

func (ServerValues) ValidateIdentity added in v0.2.2

func (values ServerValues) ValidateIdentity() error

ValidateIdentity checks the optional public origin and Google sign-in, which needs both credentials and that origin. How people join is a console setting, not configuration.

type Values

type Values struct {
	Local  LocalValues  `json:"local"`
	Remote RemoteValues `json:"remote"`
}

Values keep local serving and remote delivery in separate namespaces so one file configures both modes without either reading the other's settings.

func Default

func Default() (Values, error)

func Load

func Load() (Values, error)

Load creates defaults once. The lock also serializes first-use and config edits.

func LoadFile

func LoadFile(path string) (Values, error)

LoadFile resolves defaults, a JSON file, then environment overrides. It never persists environment values. An empty path selects the machine config. Environment names are namespaced like the file so a diffx-server deployment's DIFFX_SERVER_* variables never configure the local CLI.

func Merge

func Merge(values Values, raw string) (Values, error)

func ReadFile

func ReadFile(path string) (Values, error)

ReadFile reads persisted values only. An empty path selects the machine config.

func (Values) Get added in v0.2.1

func (values Values) Get(key string) (interface{}, error)

Get returns one persisted setting by dotted path.

func (Values) RemoteConfigured added in v0.2.1

func (values Values) RemoteConfigured() bool

RemoteConfigured reports whether sync and hooks have a complete destination.

func (Values) Settings

func (values Values) Settings() (ServerSettings, error)

func (Values) Validate

func (values Values) Validate() error

Jump to

Keyboard shortcuts

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