Configuration
Static configuration for a Hemlock app is defined within the hemlock.Config
struct.
var Config = &hemlock.Config{
Name: hemlock.EnvOr("APP_NAME", "Hemlock"),
Env: hemlock.EnvOr("APP_ENV", "production"),
URL: hemlock.EnvOr("APP_URL", "localhost:9000"),
HTTP: &hemlock.HTTPConfig{
Host: hemlock.EnvOr("HOST", "0.0.0.0"),
Port: hemlock.EnvOr("PORT", "9000"),
},
// Much more not shown...
}
Extra Configuration
There is also an optional Extras
field for storing configuration not directly related to
core Hemlock functionality. For example, plugins may require additional configuration.
For example, an S3 file plugin may require AWS keys to be defined.
var Config = &hemlock.Config{
// ...
Extra: []interface{}{
&s3plugin.Config{
AccessKeyID: hemlock.EnvOrPanic("AWS_ACCESS_KEY_ID"),
AccessSecretKey: hemlock.EnvOrPanic("AWS_SECRET_KEY"),
Bucket: hemlock.EnvOrPanic("S3_BUCKET"),
}
},
}
These extra configuration objects can be resolved from the IoC container like anything else.
// Resolve config object from route
router.Get("/", func(res h.Response, dc *s3plugin.Config) h.Result {
fmt.Println(dc.Bucket)
}
// Resolve config directly from IoC container
var dc s3plugin.Config
app.Resolve(&dc)
fmt.Println(dc.Bucket)