config

package
v1.0.2 Latest Latest
Warning

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

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

Documentation

Overview

Package config loads, parses, and validates per-node settings (from environment variables) and per-cluster settings (from a JSONC config file).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateFile

func ValidateFile(path string, flags FlagOverrides) error

ValidateFile loads and validates a config file without starting the server. Node config is still loaded from env vars (and flag overrides) so that cross-cutting validations such as node_id can run.

func ValidateIdentifier

func ValidateIdentifier(value, fieldName string) error

ValidateIdentifier checks that value is lowercase alphanumeric and hyphens, with no leading/trailing/consecutive hyphens, max 32 chars.

Types

type ChunkBufferConfig

type ChunkBufferConfig struct {
	ThresholdSizeMB     int `json:"threshold_size_mb"`
	ThresholdAgeMinutes int `json:"threshold_age_minutes"`
}

type ClusterConfig

type ClusterConfig struct {
	ClusterID          string            `json:"cluster_id"`
	Storage            StorageConfig     `json:"storage"`
	HeartbeatInterval  Duration          `json:"heartbeat_interval"`
	Elector            ElectorConfig     `json:"elector"`
	Replication        ReplicationConfig `json:"replication"`
	Snapshot           SnapshotConfig    `json:"snapshot"`
	CompactionInterval Duration          `json:"compaction_interval"`
}

ClusterConfig holds per-cluster settings parsed from a JSONC config file.

func LoadClusterConfig

func LoadClusterConfig(path string) (ClusterConfig, error)

LoadClusterConfig reads a JSONC config file, strips comments, and unmarshals it.

type Config

type Config struct {
	NodeConfig
	ClusterConfig

	// EtcdClusterID is a stable FNV-1a 64-bit hash of the string ClusterID,
	// computed once at load time for use in etcd ResponseHeader.ClusterId.
	EtcdClusterID uint64
}

Config combines per-node settings (from env vars) and per-cluster settings (from a JSONC config file).

func Load

func Load(flags FlagOverrides) (*Config, error)

Load builds a fully validated Config from environment variables, the JSONC cluster config file, and any CLI flag overrides. It returns an error if the config file cannot be found/parsed or validation fails.

func (*Config) Validate

func (c *Config) Validate() error

Validate validates all config fields and returns the first error found.

type Duration

type Duration struct {
	time.Duration
}

Duration wraps time.Duration to support JSON unmarshaling from string values like "5s", "10m", "1h30m", etc.

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

type ElectorConfig

type ElectorConfig struct {
	DegradationCount      int      `json:"degradation_count"`      // default 2
	DeregistrationTimeout Duration `json:"deregistration_timeout"` // default "3m"
	PrimaryPriorTimeout   Duration `json:"primary_prior_timeout"`
}

type FlagOverrides

type FlagOverrides struct {
	ConfigPath string // --config flag
	Verbose    bool   // --verbose flag
}

FlagOverrides holds CLI flag values that override env-var defaults.

type NodeConfig

type NodeConfig struct {
	ConfigPath        string // from NETSY_CONFIG env or --config flag
	NodeID            string // NETSY_NODE_ID
	BindClient        string // NETSY_BIND_CLIENT (default :2378)
	AdvertiseClient   string // NETSY_ADVERTISE_CLIENT
	BindPeer          string // NETSY_BIND_PEER (default :2381)
	AdvertisePeer     string // NETSY_ADVERTISE_PEER
	BindElection      string // NETSY_BIND_ELECTION (default :8443)
	AdvertiseElection string // NETSY_ADVERTISE_ELECTION
	BindHealth        string // NETSY_BIND_HEALTH (default :8080)
	TLSCACert         string // NETSY_TLS_CA_CERT
	TLSServerCert     string // NETSY_TLS_SERVER_CERT
	TLSServerKey      string // NETSY_TLS_SERVER_KEY
	TLSClientCert     string // NETSY_TLS_CLIENT_CERT
	TLSClientKey      string // NETSY_TLS_CLIENT_KEY
	DataDir           string // NETSY_DATA_DIR (default /var/lib/netsy)
	Verbose           bool   // NETSY_DEBUG
}

NodeConfig holds per-node settings populated from environment variables.

func LoadNodeConfig

func LoadNodeConfig() NodeConfig

LoadNodeConfig reads environment variables and applies defaults.

type ReplicationConfig

type ReplicationConfig struct {
	Quorum           *int              `json:"quorum"`            // default -1; 0 = disabled, -1 = majority, positive = static
	DegradationCount int               `json:"degradation_count"` // default 2
	ChunkBuffer      ChunkBufferConfig `json:"chunk_buffer"`
}

type SnapshotConfig

type SnapshotConfig struct {
	ThresholdRecords    int64 `json:"threshold_records"`     // default 10000
	ThresholdSizeMB     int64 `json:"threshold_size_mb"`     // default 10000
	ThresholdAgeMinutes int64 `json:"threshold_age_minutes"` // default 0
}

type StorageConfig

type StorageConfig struct {
	Provider   string `json:"provider"` // "s3" or "gcs", default "s3"
	BucketName string `json:"bucket_name"`
	KeyPrefix  string `json:"key_prefix"`
	Class      string `json:"class"`      // default "STANDARD"
	Encryption string `json:"encryption"` // default "provider-managed"
	KMSKeyID   string `json:"kms_key_id"`
}

type TLSFiles

type TLSFiles struct {
	ServerCert *tls.Certificate
	ServerCA   *x509.CertPool
	ClientCert *tls.Certificate
	ClientCA   *x509.CertPool
}

func LoadTLSFiles

func LoadTLSFiles(c *Config) (*TLSFiles, error)

LoadTLSFiles loads the configured CA and certificate/key pairs and parses their leaf certificates for later validation.

Jump to

Keyboard shortcuts

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