Quick Start (Fixed) - Forge Database Extension
This example demonstrates the correct way to use the Forge database extension with AuthSome.
The Problem
If you try to register the database extension without configuration:
// ❌ WRONG: This will fail!
app.RegisterExtension(forgedb.NewExtension())
You'll get this error:
database: failed to load required configuration.
Error: config required but no ConfigManager available: ConfigManager not registered
The Solution
Always provide database configuration when registering the database extension:
// ✅ CORRECT: Provide database config
app.RegisterExtension(forgedb.NewExtension(
forgedb.WithDatabase(forgedb.DatabaseConfig{
Name: "default",
Type: forgedb.TypeSQLite,
DSN: "file:myapp.db?cache=shared&_fk=1",
}),
))
Running This Example
cd examples/quick-start-fixed
go run main.go
Then visit:
Key Takeaways
- Always provide database configuration via
forgedb.WithDatabase()
- Support environment variables for flexibility
- Don't rely on ConfigManager unless you explicitly register it
- This approach works everywhere - no config files needed
Alternative: Using Config Files
If you prefer config files:
import "github.com/xraph/forge/extensions/config"
// Register config extension FIRST
app.RegisterExtension(config.NewExtension(
config.WithConfigFile("config.yaml"),
))
// Then database extension can load from config
app.RegisterExtension(forgedb.NewExtension())
But the programmatic approach (shown in main.go) is simpler and more explicit.