Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrPanic = fmt.Errorf("panic:")
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options func(kernel *kernelOptions)
func WithEnvVarFolderLocation ¶ added in v1.1.1
WithEnvVarFolderLocation Specify where to look up form the env var file.
Example ¶
package main import ( "context" "github.com/chiguirez/snout" ) func main() { // Create a config struct and map using snout tags, env, json, yaml files could be used as well as envVars to // as data source to deserialize into the config struct type Config struct { Kafka struct { BrokerAddress string `snout:"broker_address"` ConsumerGroup string `snout:"consumer_group"` Topic string `snout:"topic"` } `snout:"kafka"` App struct { //... } `snout:"app"` } Run := func(ctx context.Context, config Config) { // wire your app all together using config struct } // Create your kernel struct with the function expecting a context and your config struct kernel := snout.Kernel{ RunE: Run, } // Pass a pointer to config to the kernel for it to be able to deserialize kernelBootstrap := kernel.Bootstrap( new(Config), snout.WithEnvVarFolderLocation("/etc/config/"), ) // Initialize your app and handle any error coming from it if err := kernelBootstrap.Initialize(); err != nil { if err != context.Canceled { panic(err) } } }
Output:
func WithEnvVarPrefix ¶ added in v1.1.1
WithEnvVarPrefix strips any prefix from os EnvVars to map it into Config struct.
Example ¶
package main import ( "context" "github.com/chiguirez/snout" ) func main() { // Create a config struct and map using snout tags, env, json, yaml files could be used as well as envVars to // as data source to deserialize into the config struct type Config struct { Kafka struct { BrokerAddress string `snout:"broker_address"` ConsumerGroup string `snout:"consumer_group"` Topic string `snout:"topic"` } `snout:"kafka"` App struct { //... } `snout:"app"` } Run := func(ctx context.Context, config Config) { // wire your app all together using config struct } // Create your kernel struct with the function expecting a context and your config struct kernel := snout.Kernel{ RunE: Run, } // Pass a pointer to config to the kernel for it to be able to deserialize kernelBootstrap := kernel.Bootstrap( new(Config), snout.WithEnvVarPrefix("APP"), ) // Initialize your app and handle any error coming from it if err := kernelBootstrap.Initialize(); err != nil { if err != context.Canceled { panic(err) } } }
Output:
func WithServiceName ¶ added in v1.1.1
WithServiceName creates a profile based on the service name to look up for envVar files
Example ¶
package main import ( "context" "github.com/chiguirez/snout" ) func main() { // Create a config struct and map using snout tags, env, json, yaml files could be used as well as envVars to // as data source to deserialize into the config struct type Config struct { Kafka struct { BrokerAddress string `snout:"broker_address"` ConsumerGroup string `snout:"consumer_group"` Topic string `snout:"topic"` } `snout:"kafka"` App struct { //... } `snout:"app"` } Run := func(ctx context.Context, config Config) { // wire your app all together using config struct } // Create your kernel struct with the function expecting a context and your config struct kernel := snout.Kernel{ RunE: Run, } // Pass a pointer to config to the kernel for it to be able to deserialize kernelBootstrap := kernel.Bootstrap( new(Config), snout.WithServiceName("MyCustomServiceName"), // This will look up for any file under the envVarFolderLocation with this name ) // Initialize your app and handle any error coming from it if err := kernelBootstrap.Initialize(); err != nil { if err != context.Canceled { panic(err) } } }
Output:
Click to show internal directories.
Click to hide internal directories.