config

package
v0.0.0-...-0e07ff4 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	DefaultFilecoinCopies    = 3
	MaxFilecoinDefaultCopies = model.StorageCopiesMax
)

Variables

This section is empty.

Functions

func AdminInitialPasswordFilePath

func AdminInitialPasswordFilePath(appDir string) string

AdminInitialPasswordFilePath returns the generated Admin password file path.

func DefaultFilecoinRPCURL

func DefaultFilecoinRPCURL(network string) (string, bool)

DefaultFilecoinRPCURL returns the built-in RPC URL for a Filecoin network.

func DefaultFilecoinRPCURLs

func DefaultFilecoinRPCURLs() map[string]string

DefaultFilecoinRPCURLs returns a copy of the built-in Filecoin RPC URL map.

func EnvFieldForName

func EnvFieldForName(envName string) (string, bool)

EnvFieldForName returns the config field path for a supported SYNAPS3_ env var.

func EnvManagedFieldPaths

func EnvManagedFieldPaths() map[string]string

EnvManagedFieldPaths returns recognized config fields currently controlled by env vars.

func FieldMetadataByPath

func FieldMetadataByPath() map[string]FieldMetadata

FieldMetadataByPath returns metadata keyed by dotted config field path.

func LoadFileForSettings

func LoadFileForSettings(path string) (*Config, PersistedFieldPresence, error)

LoadFileForSettings reads TOML for settings persistence without environment overlays. Runtime defaults are applied for validation and UI display, while field presence lets settings writes preserve omitted TOML fields.

func ReadAdminInitialPasswordFile

func ReadAdminInitialPasswordFile(appDir string) (string, bool, error)

ReadAdminInitialPasswordFile reads a generated Admin password if the file exists.

func Save

func Save(path string, cfg *Config) error

Save writes a generated TOML config file. Existing custom comments and formatting are not preserved.

func SaveForSettings

func SaveForSettings(path string, cfg *Config, presence PersistedFieldPresence) error

SaveForSettings writes settings TOML while preserving absent manual/read-only fields.

func WriteAdminInitialPasswordFile

func WriteAdminInitialPasswordFile(appDir, password string) (string, error)

Types

type AdminAuthBootstrap

type AdminAuthBootstrap struct {
	Password      string
	PasswordHash  string
	SessionSecret string
}

AdminAuthBootstrap contains generated local admin credentials and session secret.

func NewAdminAuthBootstrap

func NewAdminAuthBootstrap() (AdminAuthBootstrap, error)

NewAdminAuthBootstrap generates a password, bcrypt hash, and session secret.

type AdminAuthConfig

type AdminAuthConfig struct {
	Enabled       bool          `koanf:"enabled"`
	Username      string        `koanf:"username"`
	PasswordHash  string        `koanf:"password_hash"`
	SessionSecret string        `koanf:"session_secret"`
	SessionTTL    time.Duration `koanf:"session_ttl"`
}

type AdminConfig

type AdminConfig struct {
	Addr           string          `koanf:"addr"`
	TrustedProxies []string        `koanf:"trusted_proxies"`
	Auth           AdminAuthConfig `koanf:"auth"`
}

type CacheConfig

type CacheConfig struct {
	Dir            string `koanf:"dir"`
	MaxSizeGB      int    `koanf:"max_size_gb"`
	EvictionPolicy string `koanf:"eviction_policy"` // lru | manual | none
}

type Config

type Config struct {
	Server   ServerConfig   `koanf:"server"`
	S3       S3Config       `koanf:"s3"`
	Filecoin FilecoinConfig `koanf:"filecoin"`
	Database DatabaseConfig `koanf:"database"`
	Cache    CacheConfig    `koanf:"cache"`
	Worker   WorkerConfig   `koanf:"worker"`
	Logging  LoggingConfig  `koanf:"logging"`
	Admin    AdminConfig    `koanf:"admin"`
}

func DefaultConfig

func DefaultConfig() (*Config, error)

func Load

func Load(path string) (*Config, error)

Load reads configuration from a TOML file (if it exists) and overlays environment variables prefixed with SYNAPS3_.

func LoadFile

func LoadFile(path string) (*Config, error)

LoadFile reads configuration from TOML only, without environment overlays.

func LoadSource

func LoadSource(src Source) (*Config, error)

LoadSource reads configuration from a resolved source.

func (*Config) FieldValidationErrors

func (c *Config) FieldValidationErrors() []FieldError

FieldValidationErrors returns validation errors tied to dotted config paths.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks the Config for invalid or missing values and returns all validation errors joined together so the operator can fix them in one pass.

type DatabaseConfig

type DatabaseConfig struct {
	Driver       string `koanf:"driver"` // postgres | sqlite
	DSN          string `koanf:"dsn"`
	MaxOpenConns int    `koanf:"max_open_conns"`
	MaxIdleConns int    `koanf:"max_idle_conns"`
}

type FieldError

type FieldError struct {
	Field   string `json:"field"`
	Message string `json:"message"`
}

FieldError is a validation error tied to a dotted config field path.

func (FieldError) Error

func (e FieldError) Error() string

type FieldMetadata

type FieldMetadata struct {
	Label       string `json:"label"`
	Description string `json:"description"`
	Env         string `json:"env,omitempty"`
	Editable    bool   `json:"editable"`
	Secret      bool   `json:"secret"`
}

FieldMetadata describes a config field for admin settings clients.

type FilecoinConfig

type FilecoinConfig struct {
	Network              string                      `koanf:"network"` // calibration | mainnet
	RPCURL               string                      `koanf:"rpc_url"`
	PrivateKey           string                      `koanf:"private_key"`
	Source               string                      `koanf:"source"`
	WithCDN              bool                        `koanf:"with_cdn"`
	AllowPrivateNetworks bool                        `koanf:"allow_private_networks"`
	DefaultCopies        int                         `koanf:"default_copies"`
	Observability        FilecoinObservabilityConfig `koanf:"observability"`
}

type FilecoinObservabilityConfig

type FilecoinObservabilityConfig struct {
	Interval    time.Duration `koanf:"interval"`
	Timeout     time.Duration `koanf:"timeout"`
	Concurrency int           `koanf:"concurrency"`
}

type InitOptions

type InitOptions struct {
	Dir string
}

InitOptions controls app data directory initialization.

type InitResult

type InitResult struct {
	Dir                  string
	ConfigPath           string
	DatabaseDir          string
	CacheDir             string
	DefaultDir           bool
	AdminInitialPassword string
}

InitResult describes the paths created by app data directory initialization.

func InitAppDataDir

func InitAppDataDir(opts InitOptions) (InitResult, error)

InitAppDataDir creates a reference config file and runtime directories.

type LoggingConfig

type LoggingConfig struct {
	Level    string                `koanf:"level"`  // debug | info | warn | error
	Format   string                `koanf:"format"` // json | text
	S3Access LoggingS3AccessConfig `koanf:"s3_access"`
}

type LoggingS3AccessConfig

type LoggingS3AccessConfig struct {
	Enabled bool   `koanf:"enabled"`
	Level   string `koanf:"level"` // debug | info | warn | error
}

type PersistedFieldPresence

type PersistedFieldPresence struct {
	FilecoinPrivateKey     bool
	DatabaseDriver         bool
	DatabaseDSN            bool
	DatabaseMaxOpen        bool
	DatabaseMaxIdle        bool
	CacheDir               bool
	AdminAddr              bool
	AdminTrustedProxies    bool
	AdminAuthEnabled       bool
	AdminAuthUsername      bool
	AdminAuthPasswordHash  bool
	AdminAuthSessionSecret bool
	AdminAuthSessionTTL    bool
}

PersistedFieldPresence records manual/read-only fields that were explicitly present in an existing TOML file. Settings writes use it to avoid materializing defaults for fields the browser cannot edit.

type S3Config

type S3Config struct {
	Region string `koanf:"region"`
}

type ServerConfig

type ServerConfig struct {
	Port           string    `koanf:"port"`
	TLS            TLSConfig `koanf:"tls"`
	MaxConnections int       `koanf:"max_connections"`
	MaxRequests    int       `koanf:"max_requests"`
}

type Source

type Source struct {
	Path             string
	Explicit         bool
	Exists           bool
	GeneratedDefault bool
}

Source describes the config file SynapS3 should read from and persist to.

func ResolveSource

func ResolveSource(path string, explicit bool) (Source, error)

ResolveSource chooses the config source for startup and settings persistence.

type TLSConfig

type TLSConfig struct {
	Enabled  bool   `koanf:"enabled"`
	CertFile string `koanf:"cert_file"`
	KeyFile  string `koanf:"key_file"`
}

type WorkerConfig

type WorkerConfig struct {
	Upload         WorkerPoolConfig `koanf:"upload"`
	Evictor        WorkerPoolConfig `koanf:"evictor"`
	StorageCleanup WorkerPoolConfig `koanf:"storage_cleanup"`
}

type WorkerPoolConfig

type WorkerPoolConfig struct {
	Concurrency  int           `koanf:"concurrency"`
	PollInterval time.Duration `koanf:"poll_interval"`
	MaxRetries   int           `koanf:"max_retries"`
}

Jump to

Keyboard shortcuts

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