Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrPanic = fmt.Errorf("panic")
View Source
var ErrValidation = fmt.Errorf("validation error")
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options func(kernel *kernelOptions)
func WithEnvVarFolderLocation ¶
WithEnvVarFolderLocation Specify where to look up form the env var file.
Example ¶
// 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(context.Background(), 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 ¶
WithEnvVarPrefix strips any prefix from os EnvVars to map it into Config struct.
Example ¶
// 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(context.Background(), 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 ¶
WithServiceName creates a profile based on the service name to look up for envVar files
Example ¶
// 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( context.Background(), new(Config), snout.WithServiceName("MyCustomServiceName"), ) // 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.