config

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package config provides configuration management for the Omnom application.

This package handles loading, parsing, and validating application configuration from YAML files. It supports configuration for various components including:

  • Application settings (logging, pagination, snapshots)
  • Server settings (address, base URL, cookies)
  • Database configuration (type and connection parameters)
  • Storage backends (filesystem, future cloud storage)
  • SMTP email settings
  • ActivityPub federation (key management)
  • OAuth provider configuration

The configuration can be loaded from multiple locations in order of precedence:

  1. Path specified via --config flag
  2. ./config.yml in the current directory
  3. ~/.omnomrc in the user's home directory
  4. ~/.config/omnom/config.yml in the user's config directory

Example usage:

cfg, err := config.Load("config.yml")
if err != nil {
    log.Fatal(err)
}
fmt.Println("Server address:", cfg.Server.Address)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActivityPub added in v0.4.0

type ActivityPub struct {
	PubKeyPath  string `yaml:"pubkey"`
	PrivKeyPath string `yaml:"privkey"`
	PubK        *rsa.PublicKey
	PrivK       *rsa.PrivateKey
}

ActivityPub holds ActivityPub configuration including key paths.

func (*ActivityPub) ExportPrivKey added in v0.4.0

func (ap *ActivityPub) ExportPrivKey() ([]byte, error)

ExportPrivKey exports the private key in PEM format.

func (*ActivityPub) ExportPubKey added in v0.4.0

func (ap *ActivityPub) ExportPubKey() ([]byte, error)

ExportPubKey exports the public key in PEM format.

func (*ActivityPub) ParsePrivKey added in v0.4.0

func (ap *ActivityPub) ParsePrivKey(privPEM []byte) error

ParsePrivKey parses a private key from PEM format.

func (*ActivityPub) ParsePubKey added in v0.4.0

func (ap *ActivityPub) ParsePubKey(pubPEM []byte) error

ParsePubKey parses a public key from PEM format.

type App added in v0.2.0

type App struct {
	LogLevel                 string `yaml:"log_level"`
	ResultsPerPage           uint   `yaml:"results_per_page"`
	DisableSignup            bool   `yaml:"disable_signup"`
	StaticDir                string `yaml:"static_dir"` // Deprecated: use Storage.Filesystem.RootDir instead
	CreateSnapshotFromWebapp bool   `yaml:"create_snapshot_from_webapp"`
	WebappSnapshotterTimeout int    `yaml:"webapp_snapshotter_timeout"`
	DebugSQL                 bool   `yaml:"debug_sql"`
}

App holds application-specific settings.

type Config

type Config struct {
	App         App          `yaml:"app"`
	Server      Server       `yaml:"server"`
	DB          DB           `yaml:"db"`
	Feed        Feed         `yaml:"feed"`
	Storage     Storage      `yaml:"storage"`
	SMTP        SMTP         `yaml:"smtp"`
	ActivityPub *ActivityPub `yaml:"activitypub"`
	OAuth       OAuth        `yaml:"oauth"`
	// contains filtered or unexported fields
}

Config holds the application configuration.

func CreateDefaultConfig added in v0.5.0

func CreateDefaultConfig() *Config

CreateDefaultConfig returns a new Config with default values.

func Load

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

Load reads and parses the configuration from the specified file.

func (*Config) BaseURL added in v0.8.0

func (c *Config) BaseURL(u string) string

BaseURL constructs a full URL by appending the given path to the server's base URL.

func (*Config) Filename added in v0.5.0

func (c *Config) Filename() string

Filename returns the path of the loaded configuration file.

type DB added in v0.2.0

type DB struct {
	Connection string `yaml:"connection"`
	Type       string `yaml:"type"`
}

DB holds database configuration.

type Feed added in v0.6.0

type Feed struct {
	ItemsPerPage uint `yaml:"items_per_page"`
}

Feed holds feed-related configuration.

type OAuth added in v0.3.0

type OAuth map[string]OAuthEntry

OAuth maps provider names to their OAuth configurations.

type OAuthEntry added in v0.3.0

type OAuthEntry struct {
	ClientID         string   `yaml:"client_id"`
	ClientSecret     string   `yaml:"client_secret"`
	ConfigurationURL string   `yaml:"configuration_url"`
	AuthURL          string   `yaml:"auth_url"`
	TokenURL         string   `yaml:"token_url"`
	Icon             string   `yaml:"icon"`
	Scopes           []string `yaml:"scopes"`
}

OAuthEntry holds configuration for a single OAuth provider.

type SMTP added in v0.2.0

type SMTP struct {
	Host              string `yaml:"host"`
	Port              int    `yaml:"port"`
	Username          string `yaml:"username"`
	Password          string `yaml:"password"`
	Sender            string `yaml:"sender"`
	TLS               bool   `yaml:"tls"`
	TLSAllowInsecure  bool   `yaml:"tls_allow_insecure"`
	SendTimeout       int    `yaml:"send_timeout"`
	ConnectionTimeout int    `yaml:"connection_timeout"`
}

SMTP holds email server configuration.

type Server added in v0.2.0

type Server struct {
	Address          string `yaml:"address"`
	BaseURL          string `yaml:"base_url"`
	SecureCookie     bool   `yaml:"secure_cookie"`
	RemoteUserHeader string `yaml:"remote_user_header"`
}

Server holds server configuration.

type Storage added in v0.2.0

type Storage struct {
	Filesystem *StorageFilesystem `yaml:"fs"`
}

Storage holds storage backend configuration.

type StorageFilesystem added in v0.5.0

type StorageFilesystem struct {
	RootDir string `yaml:"root_dir"`
}

StorageFilesystem holds filesystem storage configuration.

Jump to

Keyboard shortcuts

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