Use custom config type

This commit is contained in:
2025-01-08 16:49:31 -05:00
parent fa0a9f4ddc
commit 86653cf589
5 changed files with 102 additions and 33 deletions

17
main.go
View File

@@ -12,15 +12,26 @@ import (
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/ambient"
)
const defaultMetricPrefix = "weather"
func main() {
ctx, cncl := signal.NotifyContext(context.Background(), os.Kill, unix.SIGTERM)
defer cncl()
// Config type for app, which implements go-app/config.AppConfig
awConfig := &ambient.AmbientLocalExporterConfig{
MetricPrefix: defaultMetricPrefix,
WeatherStations: make([]ambient.WeatherStation, 0),
}
// Read config and environment, set up logging, load up
// an appCtx, and prepare ambient weather local exporter
ctx = app.MustSetupConfigAndLogging(ctx)
aw := ambient.New(ctx).Init()
ctx, awConfig = app.MustLoadConfigInto(ctx, awConfig)
// Prepare the exporter
aw := ambient.New(ctx, awConfig).Init()
// Define and prepare the app
awApp := app.App{
AppContext: ctx,
HTTP: &app.AppHTTP{
@@ -43,7 +54,7 @@ func main() {
},
}
// Run and wait
awApp.MustRun()
<-awApp.Done()
}