Overview
TheOption type implements the functional options pattern for configuring Server instances. Options control PocketBase initialization, developer mode, and configuration injection.
Type Definition
core/server/server_options.go:23
The Option type is a function that modifies internal server options. Multiple options can be passed to New() and are applied in order.
Available Options
WithConfig
Sets the PocketBase configuration to use when creating a new PocketBase instance.*pocketbase.Config
required
PocketBase configuration object. Supports all standard PocketBase config options including
DefaultDev, DefaultDataDir, DefaultDebug, etc.core/server/server_options.go:27
WithPocketbase
Sets a fully initialized PocketBase instance to wrap instead of creating a new one.*pocketbase.PocketBase
required
Pre-initialized PocketBase instance. Useful when you need full control over PocketBase initialization or want to share an instance.
core/server/server_options.go:35
If you enable developer mode via
InDeveloperMode() but the provided PocketBase instance was created in production mode, a warning will be logged and the mode will not be changed.WithMode
Sets the developer mode flag programmatically.bool
required
true: Enable developer mode (auto-migrations, debug endpoints, verbose logging)false: Production mode (migrations disabled, minimal logging)
core/server/server_options.go:46
InDeveloperMode
Convenience function to enable developer mode (equivalent toWithMode(true)).
core/server/server_options.go:53
Side Effects:
- Logs
"π§ Developer mode"to stdout - Enables PocketBase auto-migrations
- Enables debug endpoints
InNormalMode
Convenience function to explicitly disable developer mode (equivalent toWithMode(false)).
core/server/server_options.go:61
Side Effects:
- Logs
"π Production mode"to stdout - Disables PocketBase auto-migrations
- Disables debug endpoints
Configuration Patterns
Pattern 1: Developer Mode Toggle
Pattern 2: Custom Data Directory
Pattern 3: Shared PocketBase Instance
Pattern 4: Environment-Based Configuration
Error Handling
ErrConfigurationConflict
Panic error raised when bothWithConfig and WithPocketbase are used together.
core/server/server_options.go:18
Example Error:
Order of Operations
Options are applied in the order they are passed toNew(). Later options override earlier ones:
While you can pass multiple mode options, itβs clearer to use only one. The last option always takes precedence.
See Also
- Server - Server type and methods
- PocketBase Config Docs - Available PocketBase configuration options