config

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthConfig

type AuthConfig struct {
	// Panel is the OIDC provider for web panel login and all non-render routes.
	Panel *OIDCProvider `mapstructure:"panel"`
	// RenderProviders are additional OIDC providers accepted ONLY for render endpoints.
	// Panel provider is always valid for render too (allows UI preview).
	RenderProviders []OIDCProvider `mapstructure:"render_providers"`
}

AuthConfig groups authentication configuration. Separates panel (login/UI) auth from render-only providers.

type BootstrapConfig

type BootstrapConfig struct {
	// Enabled controls whether the first user to login is auto-created as SUPERADMIN.
	// Only takes effect when the database has zero users.
	// Default: true
	Enabled bool `mapstructure:"enabled"`
}

BootstrapConfig holds first-user bootstrap configuration.

type Config

type Config struct {
	Environment string          `mapstructure:"environment"`
	Server      ServerConfig    `mapstructure:"server"`
	Database    DatabaseConfig  `mapstructure:"database"`
	Auth        *AuthConfig     `mapstructure:"auth"`
	Logging     LoggingConfig   `mapstructure:"logging"`
	Typst       TypstConfig     `mapstructure:"typst"`
	Bootstrap   BootstrapConfig `mapstructure:"bootstrap"`

	// DummyAuth is set at runtime when no OIDC providers are configured.
	// Not loaded from YAML.
	DummyAuth bool `mapstructure:"-"`

	// DummyAuthUserID is the internal DB user ID for dummy auth mode.
	// Set at runtime after seeding the dummy user.
	DummyAuthUserID string `mapstructure:"-"`

	// DevFrontendURL is the URL of the frontend dev server (e.g., http://localhost:5173).
	// When set, the backend proxies non-API requests to this URL instead of serving embedded files.
	DevFrontendURL string `mapstructure:"-"`
}

Config represents the complete application configuration.

func Load

func Load() (*Config, error)

Load reads configuration from YAML files and environment variables. Environment variables take precedence over YAML values. Env prefix: DOC_ENGINE_ (e.g., DOC_ENGINE_SERVER_PORT)

func LoadFromFile

func LoadFromFile(filePath string) (*Config, error)

LoadFromFile loads configuration from a specific YAML file path. Environment variables still override YAML values.

func MustLoad

func MustLoad() *Config

MustLoad loads configuration and panics on error. Use this only in main() or initialization code.

func (*Config) DiscoverAll

func (c *Config) DiscoverAll(ctx context.Context) error

DiscoverAll runs OIDC discovery for all configured providers. Providers with discovery_url will have their issuer and jwks_url populated.

func (*Config) GetPanelOIDC

func (c *Config) GetPanelOIDC() *OIDCProvider

GetPanelOIDC returns the OIDC provider for panel (login/UI) authentication.

func (*Config) GetRenderOIDCProviders

func (c *Config) GetRenderOIDCProviders() []OIDCProvider

GetRenderOIDCProviders returns all OIDC providers valid for render endpoints. Includes panel provider (if exists) plus any render-specific providers.

func (*Config) IsDummyAuth

func (c *Config) IsDummyAuth() bool

IsDummyAuth returns true if no OIDC providers are configured.

type DatabaseConfig

type DatabaseConfig struct {
	Host               string `mapstructure:"host"`
	Port               int    `mapstructure:"port"`
	User               string `mapstructure:"user"`
	Password           string `mapstructure:"password"`
	Name               string `mapstructure:"name"`
	SSLMode            string `mapstructure:"ssl_mode"`
	MaxPoolSize        int    `mapstructure:"max_pool_size"`
	MinPoolSize        int    `mapstructure:"min_pool_size"`
	MaxIdleTimeSeconds int    `mapstructure:"max_idle_time_seconds"`
}

DatabaseConfig holds PostgreSQL connection configuration.

func (DatabaseConfig) MaxIdleTimeDuration

func (d DatabaseConfig) MaxIdleTimeDuration() time.Duration

MaxIdleTimeDuration returns the max idle time as time.Duration.

type GroupConfig

type GroupConfig struct {
	Key   string
	Name  string
	Icon  string
	Order int
}

GroupConfig represents a resolved group with localized name.

type InjectorI18nConfig

type InjectorI18nConfig struct {
	// contains filtered or unexported fields
}

InjectorI18nConfig contiene todas las traducciones de inyectores.

func LoadBuiltinInjectorI18n

func LoadBuiltinInjectorI18n() (*InjectorI18nConfig, error)

LoadBuiltinInjectorI18n loads the embedded built-in i18n translations. This includes datetime injectors and other built-in injectors.

func LoadInjectorI18n

func LoadInjectorI18n() (*InjectorI18nConfig, error)

LoadInjectorI18n carga traducciones desde settings/injectors.i18n.yaml. Si el archivo no existe, retorna un config vacío (el archivo es opcional).

func LoadInjectorI18nFromFile

func LoadInjectorI18nFromFile(filePath string) (*InjectorI18nConfig, error)

LoadInjectorI18nFromFile loads injector translations from a specific file path.

func (*InjectorI18nConfig) Codes

func (c *InjectorI18nConfig) Codes() []string

Codes retorna todos los codes con traducciones.

func (*InjectorI18nConfig) GetAllDescriptions

func (c *InjectorI18nConfig) GetAllDescriptions(code string) map[string]string

GetAllDescriptions retorna todas las traducciones de la descripción para un code. Si no existe el code, retorna un mapa vacío.

func (*InjectorI18nConfig) GetAllNames

func (c *InjectorI18nConfig) GetAllNames(code string) map[string]string

GetAllNames retorna todas las traducciones del nombre para un code. Si no existe el code, retorna un mapa con solo el code como fallback.

func (*InjectorI18nConfig) GetDescription

func (c *InjectorI18nConfig) GetDescription(code, locale string) string

GetDescription retorna la descripción traducida del inyector. Fallback: locale "en" → cadena vacía si no existe.

func (*InjectorI18nConfig) GetGroup

func (c *InjectorI18nConfig) GetGroup(code string) *string

GetGroup retorna el grupo al que pertenece un inyector. Retorna nil si el inyector no tiene grupo asignado.

func (*InjectorI18nConfig) GetGroups

func (c *InjectorI18nConfig) GetGroups(locale string) []GroupConfig

GetGroups retorna todos los grupos traducidos al locale especificado. El orden se determina por la posición en el array YAML (índice = orden).

func (*InjectorI18nConfig) GetName

func (c *InjectorI18nConfig) GetName(code, locale string) string

GetName retorna el nombre traducido del inyector. Fallback: locale "en" → code si no existe.

func (*InjectorI18nConfig) HasEntry

func (c *InjectorI18nConfig) HasEntry(code string) bool

HasEntry verifica si existe una entrada para el code dado.

func (*InjectorI18nConfig) Merge

func (c *InjectorI18nConfig) Merge(other *InjectorI18nConfig)

Merge combines another config into this one. The other config's entries override this config's entries for the same code. Groups from other are appended after this config's groups.

type LoggingConfig

type LoggingConfig struct {
	Level  string `mapstructure:"level"`
	Format string `mapstructure:"format"`
}

LoggingConfig holds logging configuration.

type OIDCProvider

type OIDCProvider struct {
	Name         string `mapstructure:"name"`          // Human-readable name for logging
	DiscoveryURL string `mapstructure:"discovery_url"` // OpenID Connect discovery URL (optional)
	Issuer       string `mapstructure:"issuer"`        // Expected token issuer (iss claim)
	JWKSURL      string `mapstructure:"jwks_url"`      // JWKS endpoint URL
	Audience     string `mapstructure:"audience"`      // Optional audience (aud claim)

	// Frontend OIDC endpoints (populated from discovery or manual config)
	TokenEndpoint      string `mapstructure:"token_endpoint"`       // Token endpoint URL
	UserinfoEndpoint   string `mapstructure:"userinfo_endpoint"`    // Userinfo endpoint URL
	EndSessionEndpoint string `mapstructure:"end_session_endpoint"` // Logout/end session endpoint URL
	ClientID           string `mapstructure:"client_id"`            // OIDC client ID for frontend
}

OIDCProvider represents a single OIDC identity provider configuration.

type ServerConfig

type ServerConfig struct {
	Port            string `mapstructure:"port"`
	ReadTimeout     int    `mapstructure:"read_timeout"`
	WriteTimeout    int    `mapstructure:"write_timeout"`
	ShutdownTimeout int    `mapstructure:"shutdown_timeout"`
	SwaggerUI       bool   `mapstructure:"swagger_ui"`
}

ServerConfig holds HTTP server configuration.

func (ServerConfig) ReadTimeoutDuration

func (s ServerConfig) ReadTimeoutDuration() time.Duration

ReadTimeoutDuration returns the read timeout as time.Duration.

func (ServerConfig) ShutdownTimeoutDuration

func (s ServerConfig) ShutdownTimeoutDuration() time.Duration

ShutdownTimeoutDuration returns the shutdown timeout as time.Duration.

func (ServerConfig) WriteTimeoutDuration

func (s ServerConfig) WriteTimeoutDuration() time.Duration

WriteTimeoutDuration returns the write timeout as time.Duration.

type TypstConfig

type TypstConfig struct {
	BinPath                  string   `mapstructure:"bin_path"`
	TimeoutSeconds           int      `mapstructure:"timeout_seconds"`
	FontDirs                 []string `mapstructure:"font_dirs"`
	MaxConcurrent            int      `mapstructure:"max_concurrent"`
	AcquireTimeoutSeconds    int      `mapstructure:"acquire_timeout_seconds"`
	TemplateCacheTTL         int      `mapstructure:"template_cache_ttl_seconds"`
	TemplateCacheMax         int      `mapstructure:"template_cache_max_entries"`
	ImageCacheDir            string   `mapstructure:"image_cache_dir"`
	ImageCacheMaxAgeSeconds  int      `mapstructure:"image_cache_max_age_seconds"`
	ImageCacheCleanupSeconds int      `mapstructure:"image_cache_cleanup_interval_seconds"`
}

TypstConfig holds Typst renderer configuration.

func (TypstConfig) AcquireTimeoutDuration

func (t TypstConfig) AcquireTimeoutDuration() time.Duration

AcquireTimeoutDuration returns the acquire timeout as time.Duration.

func (TypstConfig) TimeoutDuration

func (t TypstConfig) TimeoutDuration() time.Duration

TimeoutDuration returns the timeout as time.Duration.

Jump to

Keyboard shortcuts

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