65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"os/signal"
|
|
|
|
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/app"
|
|
"golang.org/x/sys/unix"
|
|
|
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/ambient"
|
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/ambient/config"
|
|
)
|
|
|
|
const (
|
|
defaultMetricPrefix = "weather"
|
|
)
|
|
|
|
var schema bool
|
|
|
|
func main() {
|
|
ctx, cncl := signal.NotifyContext(context.Background(), os.Kill, os.Interrupt, unix.SIGTERM)
|
|
defer cncl()
|
|
|
|
// Read config and environment, prepare an appCtx, and merge
|
|
// go-app config into ambient weather exporter app config
|
|
ctx, awConfig := app.MustLoadConfigInto(ctx, &config.AmbientLocalExporterConfig{
|
|
MetricPrefix: defaultMetricPrefix,
|
|
WeatherStations: make([]config.WeatherStation, 0),
|
|
})
|
|
|
|
// Prepare the ambient exporter with our prepared config
|
|
// and set up logging, tracing, etc..
|
|
aw := ambient.New(ctx, awConfig).Init()
|
|
|
|
// Just show schema if that's all we were asked to do
|
|
if schema {
|
|
printSchema(awConfig)
|
|
os.Exit(0)
|
|
}
|
|
|
|
// Load http and grpc routes, prepare the app
|
|
awApp := prepareApp(ctx, aw)
|
|
|
|
// Run app and wait
|
|
awApp.MustRun()
|
|
<-awApp.Done()
|
|
}
|
|
|
|
// flag.Parse will be called by go-app
|
|
func init() {
|
|
flag.BoolVar(&schema, "schema", false, "generate json schema and exit")
|
|
}
|
|
|
|
func printSchema(config *config.AmbientLocalExporterConfig) {
|
|
bytes, err := app.CustomSchema(config)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
fmt.Println(string(bytes))
|
|
}
|