config

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 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 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 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 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"`
	State           string `json:"state"`
	Username        string `json:"username"`
	SignupEnabled   bool   `json:"signupEnabled"`
	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"`
}

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.

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