2021-07-20 12:18:00 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-07-20 12:25:05 +02:00
|
|
|
"flag"
|
2021-07-21 01:33:54 +02:00
|
|
|
"net/http"
|
2021-07-20 12:18:00 +02:00
|
|
|
|
|
|
|
"dev.sum7.eu/genofire/golang-lib/file"
|
2021-07-21 01:33:54 +02:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
2021-09-29 14:03:25 +02:00
|
|
|
"go.uber.org/zap"
|
2021-07-21 00:15:57 +02:00
|
|
|
|
|
|
|
"dev.sum7.eu/genofire/oven-exporter/api"
|
2021-07-20 12:18:00 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type configData struct {
|
2021-09-29 14:03:25 +02:00
|
|
|
log *zap.Logger
|
|
|
|
Log *zap.Config `toml:"log"`
|
2021-07-21 01:33:54 +02:00
|
|
|
API *api.Client `toml:"api"`
|
|
|
|
Listen string `toml:"listen"`
|
2021-07-20 12:18:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
configPath := "config.toml"
|
|
|
|
|
2021-12-28 18:08:53 +01:00
|
|
|
log, _ := zap.NewProduction()
|
2021-09-29 14:03:25 +02:00
|
|
|
|
2021-07-20 12:18:00 +02:00
|
|
|
flag.StringVar(&configPath, "c", configPath, "path to configuration file")
|
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
config := &configData{}
|
|
|
|
if err := file.ReadTOML(configPath, config); err != nil {
|
2021-09-29 14:03:25 +02:00
|
|
|
log.Panic("open config file", zap.Error(err))
|
|
|
|
}
|
|
|
|
if config.Log != nil {
|
|
|
|
l, err := config.Log.Build()
|
|
|
|
if err != nil {
|
|
|
|
log.Panic("generate logger from config", zap.Error(err))
|
|
|
|
}
|
|
|
|
log = l
|
2021-07-20 12:18:00 +02:00
|
|
|
}
|
2021-09-29 14:03:25 +02:00
|
|
|
config.log = log
|
|
|
|
//config.SetLogger(log)
|
2021-07-21 00:15:57 +02:00
|
|
|
config.API.SetToken(config.API.Token)
|
2021-07-21 01:33:54 +02:00
|
|
|
|
|
|
|
prometheus.MustRegister(config)
|
|
|
|
http.Handle("/metrics", promhttp.Handler())
|
2021-09-29 14:03:25 +02:00
|
|
|
if err := http.ListenAndServe(config.Listen, nil); err != nil {
|
|
|
|
log.Fatal("crash webserver", zap.Error(err))
|
|
|
|
}
|
2021-07-20 12:18:00 +02:00
|
|
|
}
|