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

config

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingIMAPHost is returned when IMAP host is not configured
	ErrMissingIMAPHost = errors.New("IMAP_HOST is required: set via environment variable or config file")
	// ErrMissingIMAPUsername is returned when IMAP username is not configured
	ErrMissingIMAPUsername = errors.New("IMAP_USERNAME is required: set via environment variable or config file")
	// ErrMissingIMAPPassword is returned when IMAP password is not configured
	ErrMissingIMAPPassword = errors.New("IMAP_PASSWORD is required: set via environment variable or config file")
)

Functions

func GenerateSample

func GenerateSample(path string) error

GenerateSample creates a sample configuration file

Types

type Config

type Config struct {
	LogLevel    string         `json:"log_level" env:"LOG_LEVEL" envDefault:"info"`
	ColoredLogs bool           `json:"colored_logs" env:"COLORED_LOGS" envDefault:"false"`
	IMAP        IMAPConfig     `json:"imap"`
	Maildir     MaildirConfig  `json:"maildir"`
	Database    DatabaseConfig `json:"database"`
	Server      ServerConfig   `json:"server"`
}

Config holds the application configuration

func Load

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

Load loads configuration from a JSON file

func (*Config) Validate

func (c *Config) Validate() error

Validate checks that all required configuration values are set. Required fields: IMAP host, username, and password, unless a Maildir replaces the mailbox and the fetch does not touch IMAP at all. Returns nil if valid, or an error describing the missing configuration.

type DatabaseConfig

type DatabaseConfig struct {
	Path string `json:"path" env:"DATABASE_PATH"`
}

DatabaseConfig holds database configuration

type IMAPConfig

type IMAPConfig struct {
	Host     string `json:"host" env:"IMAP_HOST"`
	Port     int    `json:"port" env:"IMAP_PORT" envDefault:"993"`
	Username string `json:"username" env:"IMAP_USERNAME"`
	Password string `json:"password" env:"IMAP_PASSWORD"`
	Mailbox  string `json:"mailbox" env:"IMAP_MAILBOX" envDefault:"INBOX"`
	UseTLS   bool   `json:"use_tls" env:"IMAP_USE_TLS" envDefault:"true"`

	// StartTLS dials plaintext (typically port 143) and upgrades the
	// connection with the STARTTLS command. It takes precedence over UseTLS.
	StartTLS bool `json:"starttls" env:"IMAP_STARTTLS"`
	// TLSCAFile is a PEM bundle used to verify the IMAP server certificate,
	// for servers whose certificate is issued by an internal CA.
	TLSCAFile string `json:"tls_ca_file" env:"IMAP_TLS_CA_FILE"`
	// TLSSkipVerify disables IMAP server certificate verification. Prefer
	// TLSCAFile; this leaves the connection open to interception.
	TLSSkipVerify bool `json:"tls_skip_verify" env:"IMAP_TLS_SKIP_VERIFY"`

	MarkAsSeen       bool   `json:"mark_as_seen" env:"IMAP_MARK_AS_SEEN" envDefault:"true"`
	ProcessedMailbox string `json:"processed_mailbox" env:"IMAP_PROCESSED_MAILBOX"`
}

IMAPConfig holds IMAP server configuration

type MaildirConfig

type MaildirConfig struct {
	Path string `json:"path" env:"MAILDIR_PATH"`
	// DeadletterMailbox is the subdirectory of Path that receives every
	// message no report could be read from, so the operator sees what the
	// parser dropped instead of it passing as processed.
	DeadletterMailbox string `json:"deadletter_mailbox" env:"IMAP_DEADLETTER_BOX" envDefault:"DEADLETTER"`
}

MaildirConfig holds local Maildir intake configuration. When Path is set, reports are read from <Path>/new and moved to <Path>/cur instead of being fetched over IMAP, and no IMAP credentials are needed.

type ServerConfig

type ServerConfig struct {
	Port int    `json:"port" env:"SERVER_PORT" envDefault:"8080"`
	Host string `json:"host" env:"SERVER_HOST" envDefault:""`
}

ServerConfig holds web server configuration

Jump to

Keyboard shortcuts

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