ambient-local-exporter/main.go

62 lines
1.5 KiB
Go
Raw Normal View History

2025-01-04 18:15:19 +00:00
package main
import (
"context"
"os"
"os/signal"
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/app"
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv"
"golang.org/x/sys/unix"
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/ambient"
2025-01-12 22:23:32 +00:00
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/ambient/config"
2025-01-04 18:15:19 +00:00
)
2025-01-08 21:49:31 +00:00
const defaultMetricPrefix = "weather"
2025-01-04 18:15:19 +00:00
func main() {
ctx, cncl := signal.NotifyContext(context.Background(), os.Kill, unix.SIGTERM)
defer cncl()
2025-01-08 21:49:31 +00:00
// Config type for app, which implements go-app/config.AppConfig
2025-01-12 22:23:32 +00:00
awConfig := &config.AmbientLocalExporterConfig{
2025-01-08 21:49:31 +00:00
MetricPrefix: defaultMetricPrefix,
2025-01-12 22:23:32 +00:00
WeatherStations: make([]config.WeatherStation, 0),
2025-01-08 21:49:31 +00:00
}
2025-01-07 15:27:02 +00:00
// Read config and environment, set up logging, load up
// an appCtx, and prepare ambient weather local exporter
2025-01-08 21:49:31 +00:00
ctx, awConfig = app.MustLoadConfigInto(ctx, awConfig)
2025-01-05 01:54:36 +00:00
2025-01-08 21:49:31 +00:00
// Prepare the exporter
aw := ambient.New(ctx, awConfig).Init()
// Define and prepare the app
2025-01-04 18:15:19 +00:00
awApp := app.App{
AppContext: ctx,
HTTP: &app.AppHTTP{
Funcs: []srv.HTTPFunc{
{
Path: "/weatherstation/updateweatherstation.php",
2025-01-05 01:54:36 +00:00
HandlerFunc: aw.GetWundergroundHandlerFunc(ctx),
2025-01-04 18:15:19 +00:00
},
{
Path: "/data/report",
2025-01-05 01:54:36 +00:00
HandlerFunc: aw.GetAWNHandlerFunc(ctx),
2025-01-04 18:15:19 +00:00
},
},
HealthChecks: []srv.HealthCheckFunc{
// TODO: Implement
func(ctx context.Context) error {
return nil
},
},
},
}
2025-01-08 21:49:31 +00:00
// Run and wait
2025-01-04 18:15:19 +00:00
awApp.MustRun()
<-awApp.Done()
}