8e66e55119
DRAFT PR: Prototype for serviceconfig * in progress * in progress * extract common methods * Merge remote-tracking branch 'origin/feature/serviceconfig' into feature/serviceconfig * fix types * cleanup * add tests * Merged main into feature/serviceconfig Approved-by: Michael McGuinness
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"queryorchestration/internal/serviceconfig"
|
|
)
|
|
|
|
// Note: All that a service needs to have its own config is to create a new
|
|
// config type (any name you want) and add your customer variables to it that
|
|
// then call the serviceconfig.InitializeConfig() function on it.
|
|
type AnyServiceNameConfig struct {
|
|
// BaseConfig has all of the common base configuration that all services should have
|
|
// we can adjust what is in there as needed.
|
|
serviceconfig.BaseConfig // Embed the base configuration
|
|
|
|
// add any custom values that this service needs
|
|
AppEnv string `env:"APP_ENV"`
|
|
}
|
|
|
|
// main
|
|
// Dead simple example of of how to initialize a service custom config - AnyServiceNameConfig object in any project code.
|
|
func main() {
|
|
|
|
// create your own customer service config
|
|
cfg := &AnyServiceNameConfig{}
|
|
// and let the shared code initialize it for you correctly.
|
|
if err := serviceconfig.InitializeConfig(cfg); err != nil {
|
|
fmt.Printf("Error initializing the custom config (see output): %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
fmt.Printf("config: %+v\n", cfg)
|
|
cfg.Logger.Info("Service initialized ok.")
|
|
|
|
}
|