Skip to main content

Overview

The Option type implements the functional options pattern for configuring Server instances. Options control PocketBase initialization, developer mode, and configuration injection.

Type Definition

Location: 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.
Parameters:
*pocketbase.Config
required
PocketBase configuration object. Supports all standard PocketBase config options including DefaultDev, DefaultDataDir, DefaultDebug, etc.
Example:
Location: core/server/server_options.go:27
Cannot be used with WithPocketbase. These options are mutually exclusive. Using both will cause a panic with ErrConfigurationConflict.

WithPocketbase

Sets a fully initialized PocketBase instance to wrap instead of creating a new one.
Parameters:
*pocketbase.PocketBase
required
Pre-initialized PocketBase instance. Useful when you need full control over PocketBase initialization or want to share an instance.
Example:
Location: core/server/server_options.go:35
Cannot be used with WithConfig. If a config is already set, this option will panic with ErrConfigurationConflict.
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.
Parameters:
bool
required
  • true: Enable developer mode (auto-migrations, debug endpoints, verbose logging)
  • false: Production mode (migrations disabled, minimal logging)
Example:
Location: core/server/server_options.go:46

InDeveloperMode

Convenience function to enable developer mode (equivalent to WithMode(true)).
Example:
Location: 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 to WithMode(false)).
Example:
Location: 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 both WithConfig and WithPocketbase are used together.
Location: core/server/server_options.go:18 Example Error:
Solution:

Order of Operations

Options are applied in the order they are passed to New(). 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