settings

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRedisAddress = "127.0.0.1:6379"
	DefaultCacheDir     = "cache"
)
View Source
const (
	DefaultEmailDir     = "mail"
	DefaultEmailTimeout = 10 * time.Second
)
View Source
const DefaultCSP = "default-src 'self'; " +
	"script-src 'self' {nonce}; " +
	"style-src 'self' {nonce}; " +
	"img-src 'self' data:; " +
	"object-src 'none'; " +
	"base-uri 'self'; " +
	"frame-ancestors 'none'"
View Source
const DefaultFrameOptions = "DENY"
View Source
const DefaultPermissionsPolicy = "camera=(), microphone=(), geolocation=()"
View Source
const DefaultSQLiteName = "coyote.db"

Variables

This section is empty.

Functions

func Env

func Env(key, fallback string) string

func EnvBool

func EnvBool(key string, fallback bool) bool

func EnvDuration

func EnvDuration(key string, fallback time.Duration) time.Duration

func EnvInt

func EnvInt(key string, fallback int) int

func EnvList

func EnvList(key string, fallback []string) []string

func GenerateSecretKey

func GenerateSecretKey() (string, error)

func IsConfigured

func IsConfigured() bool

func Load

func Load(sources ...Source) error

func LoadDotEnv

func LoadDotEnv(paths ...string) error

func MustLoad

func MustLoad(sources ...Source)

func MustLoadDotEnv

func MustLoadDotEnv(paths ...string)

func Preset

func Preset(name string) func(*Settings)

func Reset

func Reset()

Types

type Admin

type Admin struct {
	Prefix   string
	SiteName string
	Tagline  string
}

type Auth

type Auth struct {
	LoginURL            string
	PasswordMinLength   int
	PasswordRules       []auth.PasswordRule
	PBKDF2Iterations    int
	Throttle            auth.ThrottlePolicy
	Permissions         bool
	AllowPasswordChange bool
	ResetTokens         bool
	ResetTokenLifetime  time.Duration
	UserStore           auth.Store
	PermissionStore     auth.PermissionStore
}

type CORS

type CORS struct {
	Origins          []string
	Methods          []string
	Headers          []string
	ExposeHeaders    []string
	AllowCredentials bool
	MaxAge           time.Duration
}

func (CORS) AllowsAnyOrigin

func (c CORS) AllowsAnyOrigin() bool

func (CORS) Enabled

func (c CORS) Enabled() bool

func (CORS) HeaderList

func (c CORS) HeaderList() []string

func (CORS) MethodList

func (c CORS) MethodList() []string

type Cache

type Cache struct {
	Alias   string
	Backend CacheBackend
	TTL     time.Duration
	Prefix  string
	Version string

	Address  string
	Username string
	Password string
	Database int
	TLS      *tls.Config

	Dir string

	MaxEntries      int
	MaxBytes        int64
	CleanupInterval time.Duration
	PoolSize        int
	DialTimeout     time.Duration
	ReadTimeout     time.Duration
	WriteTimeout    time.Duration

	Store cache.Cache
}

func MemoryCache

func MemoryCache(alias string) Cache

func RedisCache

func RedisCache(alias, address string) Cache

func (Cache) IsFile

func (c Cache) IsFile() bool

func (Cache) IsMemory

func (c Cache) IsMemory() bool

func (Cache) IsRedis

func (c Cache) IsRedis() bool

func (Cache) Location

func (c Cache) Location() string

func (Cache) Redacted

func (c Cache) Redacted() Cache

type CacheBackend

type CacheBackend string
const (
	CacheInMemory CacheBackend = "memory"
	CacheInRedis  CacheBackend = "redis"
	CacheInFile   CacheBackend = "file"
)

type Database

type Database struct {
	Alias           string
	Engine          Engine
	Name            string
	Host            string
	Port            int
	User            string
	Password        string
	Options         map[string]string
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime time.Duration
	ConnMaxIdleTime time.Duration
}

func SQLiteDatabase

func SQLiteDatabase(alias, name string) Database

func (Database) DSN

func (d Database) DSN() string

func (Database) IsSQLite

func (d Database) IsSQLite() bool

func (Database) Redacted

func (d Database) Redacted() Database

type Email

type Email struct {
	Backend   EmailBackend
	Host      string
	Port      int
	Username  string
	Password  string
	TLS       mail.TLSMode
	From      string
	Dir       string
	Timeout   time.Duration
	LocalName string

	Sender mail.Sender
}

func (Email) Enabled

func (e Email) Enabled() bool

func (Email) Location

func (e Email) Location() string

func (Email) Open

func (e Email) Open() (mail.Sender, error)

func (Email) Redacted

func (e Email) Redacted() Email

type EmailBackend

type EmailBackend string
const (
	EmailToSMTP    EmailBackend = "smtp"
	EmailToConsole EmailBackend = "console"
	EmailToFile    EmailBackend = "file"
	EmailToMemory  EmailBackend = "memory"
)

type Engine

type Engine string
const (
	SQLite   Engine = "sqlite"
	Postgres Engine = "postgres"
	MySQL    Engine = "mysql"
)

type File

type File struct {
	Path     string
	Optional bool
}

func DotEnv

func DotEnv(path string) File

func RequiredDotEnv

func RequiredDotEnv(path string) File

func (File) Name

func (f File) Name() string

func (File) Values

func (f File) Values() (map[string]string, error)

type I18N

type I18N struct {
	Default    string
	Supported  []string
	Dir        string
	FS         fs.FS
	Fallbacks  map[string]string
	URLPrefix  bool
	CookieName string
	Loader     i18n.Loader
	Formatter  i18n.Formatter
}

func (I18N) Cookie

func (i I18N) Cookie() string

func (I18N) Enabled

func (i I18N) Enabled() bool

func (I18N) Locale

func (i I18N) Locale() string

type ImproperlyConfigured

type ImproperlyConfigured struct {
	Problems []string
}

func (*ImproperlyConfigured) Error

func (e *ImproperlyConfigured) Error() string

type Jobs

type Jobs struct {
	Enabled        bool
	Queue          jobs.Queue
	Queues         []string
	Workers        int
	MaxAttempts    int
	Backoff        time.Duration
	BackoffCeiling time.Duration
	ClaimTimeout   time.Duration
	DrainTimeout   time.Duration
	PollInterval   time.Duration
	DoneTTL        time.Duration
}

func (Jobs) Active

func (j Jobs) Active() bool

func (Jobs) QueueNames

func (j Jobs) QueueNames() []string

func (Jobs) RunsWorkers

func (j Jobs) RunsWorkers() bool

type Logging

type Logging struct {
	Level  string
	Format string
	Logger *slog.Logger
}

type Map

type Map map[string]string

func (Map) Name

func (m Map) Name() string

func (Map) Values

func (m Map) Values() (map[string]string, error)

type Migrations

type Migrations struct {
	Dir string
}

type PageCache

type PageCache struct {
	Enabled bool
	Alias   string
	TTL     time.Duration
	Paths   []string
	Skip    []string
	Vary    []string
}

func (PageCache) Active

func (p PageCache) Active() bool

type Pagination

type Pagination struct {
	PerPage   int
	Paginator view.Paginator
}

type Profile

type Profile string
const (
	Development Profile = "development"
	Staging     Profile = "staging"
	Production  Profile = "production"
)

func ParseProfile

func ParseProfile(name string) (Profile, bool)

func (Profile) Apply

func (p Profile) Apply(s *Settings)

func (Profile) Deployed

func (p Profile) Deployed() bool

type RateLimit

type RateLimit struct {
	Requests int
	Window   time.Duration
	Burst    int
}

func (RateLimit) Capacity

func (r RateLimit) Capacity() int

func (RateLimit) Enabled

func (r RateLimit) Enabled() bool

type SameSite

type SameSite string
const (
	SameSiteLax    SameSite = "lax"
	SameSiteStrict SameSite = "strict"
	SameSiteNone   SameSite = "none"
)

type Security

type Security struct {
	TrustRequestID    bool
	TrustedProxyCount int
	FrameOptions      string
	PermissionsPolicy string
	CSRF              bool
	CSRFExempt        []string
	CSP               string
	CSPReportOnly     bool
	CORS              CORS
	Compress          bool
	CompressLevel     int
	RateLimit         RateLimit
}

type Server

type Server struct {
	Host              string
	Port              int
	MaxBodyBytes      int64
	ReadTimeout       time.Duration
	WriteTimeout      time.Duration
	IdleTimeout       time.Duration
	ReadHeaderTimeout time.Duration
	ShutdownTimeout   time.Duration
	TLS               TLS
	Configure         func(*http.Server)
}

func (Server) Addr

func (s Server) Addr() string

type SessionBackend

type SessionBackend string
const (
	SessionsInMemory SessionBackend = "memory"
	SessionsInDB     SessionBackend = "database"
	SessionsInCookie SessionBackend = "cookie"
)

func (SessionBackend) Persistent

func (b SessionBackend) Persistent() bool

func (SessionBackend) Stateless

func (b SessionBackend) Stateless() bool

type Sessions

type Sessions struct {
	Backend         SessionBackend
	CookieName      string
	Lifetime        time.Duration
	Rolling         bool
	Secure          bool
	HTTPOnly        bool
	SameSite        SameSite
	Path            string
	Domain          string
	CleanupInterval time.Duration
	Store           session.Store
}

type Settings

type Settings struct {
	Debug        bool
	Environment  Profile
	SecretKey    string
	AllowedHosts []string
	BaseDir      string

	Databases []Database
	Caches    []Cache

	Server     Server
	Security   Security
	Migrations Migrations
	Sessions   Sessions
	Auth       Auth
	I18N       I18N
	TimeZone   string
	Templates  Templates
	PageCache  PageCache
	Pagination Pagination
	Uploads    Uploads
	Static     Static
	Admin      Admin
	Logging    Logging
	Email      Email
	Jobs       Jobs
	// contains filtered or unexported fields
}

func Configure

func Configure(fns ...func(*Settings)) Settings

func Default

func Default() Settings

func Get

func Get() Settings

func New

func New(fns ...func(*Settings)) (Settings, error)

func (Settings) Addr

func (s Settings) Addr() string

func (Settings) AutoReloadTemplates

func (s Settings) AutoReloadTemplates() bool

func (Settings) BaseURL

func (s Settings) BaseURL() string

func (Settings) Cache

func (s Settings) Cache() Cache

func (Settings) CacheByAlias

func (s Settings) CacheByAlias(alias string) (Cache, bool)

func (Settings) CommandOverrides

func (s Settings) CommandOverrides() []string

func (Settings) Database

func (s Settings) Database() Database

func (Settings) DatabaseByAlias

func (s Settings) DatabaseByAlias(alias string) (Database, bool)

func (Settings) IsDeployed

func (s Settings) IsDeployed() bool

func (Settings) IsDevelopment

func (s Settings) IsDevelopment() bool

func (Settings) IsProduction

func (s Settings) IsProduction() bool

func (Settings) IsStaging

func (s Settings) IsStaging() bool

func (Settings) LogLevel

func (s Settings) LogLevel() slog.Level

func (Settings) Path

func (s Settings) Path(elements ...string) string

func (Settings) Scheme

func (s Settings) Scheme() string

func (Settings) SecretKeyGenerated

func (s Settings) SecretKeyGenerated() bool

type Source

type Source interface {
	Name() string
	Values() (map[string]string, error)
}

type Static

type Static struct {
	URL string
	FS  fs.FS
	Dir string
}

type TLS

type TLS struct {
	CertFile   string
	KeyFile    string
	MinVersion uint16
	HSTS       time.Duration
	Config     *tls.Config
	Autocert   bool
	AcceptTOS  bool
	CacheDir   string
	Staging    bool
}

func (TLS) Build

func (t TLS) Build() *tls.Config

func (TLS) Enabled

func (t TLS) Enabled() bool

func (TLS) Managed

func (t TLS) Managed() bool

func (TLS) Scheme

func (t TLS) Scheme() string

func (TLS) Version

func (t TLS) Version() uint16

type Templates

type Templates struct {
	FS     fs.FS
	Dir    string
	Layout string
	Shared []string
	Funcs  template.FuncMap
}

type Uploads

type Uploads struct {
	Enabled      bool
	Dir          string
	Path         string
	MaxSize      int64
	Allowed      []string
	MaxPixels    int
	Serve        bool
	URL          string
	Private      bool
	SignedURLTTL time.Duration
	StageTTL     time.Duration
	TrashTTL     time.Duration
	Storage      storage.Storage
}

Jump to

Keyboard shortcuts

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