config

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(cfg *Config) (*gorm.DB, error)

func Load

func Load(target any) error

func Migrate

func Migrate(db *gorm.DB) error

Types

type Config

type Config struct {
	Port                    int           `mapstructure:"PORT"`
	Env                     string        `mapstructure:"ENV"`
	JWTSecret               string        `mapstructure:"JWT_SECRET"`
	JWTTokenDuration        time.Duration `mapstructure:"JWT_TOKEN_DURATION"`
	JWTRefreshTokenDuration time.Duration `mapstructure:"JWT_REFRESH_TOKEN_DURATION"`
	MagicLinkTokenDuration  time.Duration `mapstructure:"MAGIC_LINK_TOKEN_DURATION"`
	DatabaseURL             string        `mapstructure:"DATABASE_URL"`
	DatabaseLogLevel        string        `mapstructure:"DATABASE_LOG_LEVEL"`
	DatabaseMaxIdleConns    int           `mapstructure:"DATABASE_MAX_IDLE_CONNS"`
	DatabaseMaxOpenConns    int           `mapstructure:"DATABASE_MAX_OPEN_CONNS"`
	DatabaseConnMaxLifetime time.Duration `mapstructure:"DATABASE_CONN_MAX_LIFETIME"`
	AppBaseURL              string        `mapstructure:"APP_BASE_URL"`
	FreeNoteLimit           int           `mapstructure:"FREE_NOTE_LIMIT"`
	RateLimitPerMinute      int           `mapstructure:"RATE_LIMIT_PER_MINUTE"`
	RateLimitBurst          int           `mapstructure:"RATE_LIMIT_BURST"`
	ResendAPIKey            string        `mapstructure:"RESEND_API_KEY"`
	EmailFrom               string        `mapstructure:"EMAIL_FROM"`

	// CORSAllowedOrigins is a comma-separated list of origins the server will
	// reflect in Access-Control-Allow-Origin responses. Set via CORS_ALLOWED_ORIGINS.
	// Use ParsedCORSOrigins() to obtain the split slice for use in middleware.
	CORSAllowedOrigins string `mapstructure:"CORS_ALLOWED_ORIGINS"`

	// MaxRequestBody is the maximum size of an incoming request body, expressed
	// in Echo's BodyLimit format (e.g. "1M", "512K"). Requests exceeding this
	// size are rejected with HTTP 413 before the handler is invoked.
	MaxRequestBody string `mapstructure:"MAX_REQUEST_BODY"`

	// PostHog telemetry. When POSTHOG_API_KEY is set the logging package
	// forwards warn-and-above log entries to PostHog as "server.log" events.
	// POSTHOG_ENDPOINT overrides the default US endpoint — set to
	// https://eu.i.posthog.com for EU data residency.
	// Both fields are optional; omitting them disables PostHog forwarding.
	PostHogAPIKey   string `mapstructure:"POSTHOG_API_KEY"`
	PostHogEndpoint string `mapstructure:"POSTHOG_ENDPOINT"`

	// Billing / Stripe. All fields are optional unless BillingEnabled is true,
	// in which case Validate() requires the Stripe secrets and the Resend key.
	BillingEnabled      bool   `mapstructure:"BILLING_ENABLED"`
	StripeSecretKey     string `mapstructure:"STRIPE_SECRET_KEY"`
	StripeWebhookSecret string `mapstructure:"STRIPE_WEBHOOK_SECRET"`
	StripePriceID       string `mapstructure:"STRIPE_PRICE_ID"`
	StripeSuccessURL    string `mapstructure:"STRIPE_SUCCESS_URL"`
	StripeCancelURL     string `mapstructure:"STRIPE_CANCEL_URL"`
}

func (*Config) IsDevelopment

func (c *Config) IsDevelopment() bool

func (*Config) IsProduction added in v0.4.1

func (c *Config) IsProduction() bool

func (*Config) MaxRequestBodyBytes added in v0.4.1

func (c *Config) MaxRequestBodyBytes() int64

MaxRequestBodyBytes parses the human-readable MAX_REQUEST_BODY string into bytes as int64. Supported suffixes are K (kibibytes), M (mebibytes), and G (gibibytes); a bare integer is treated as bytes. Multiplier constants come from Echo's middleware package so we stay in sync with how Echo itself counts. Parsing errors fall back silently to 1 MiB so a misconfigured value never brings the server down.

func (*Config) ParsedCORSOrigins added in v0.4.1

func (c *Config) ParsedCORSOrigins() []string

ParsedCORSOrigins splits the comma-separated CORS_ALLOWED_ORIGINS value into a slice of trimmed, non-empty origin strings ready for use in Echo's CORS middleware. Returns nil when the raw value is empty.

func (*Config) Validate

func (c *Config) Validate() error

Jump to

Keyboard shortcuts

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