Allow configuration file to be passed as parameter

This commit is contained in:
TwinProduction
2019-12-04 16:44:35 -05:00
parent 66e48609b4
commit c9c076a959
3 changed files with 51 additions and 18 deletions

20
main.go
View File

@ -8,20 +8,36 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
"log"
"net/http"
"os"
)
func main() {
go watchdog.Monitor()
cfg := loadConfiguration()
go watchdog.Monitor(cfg)
http.HandleFunc("/api/v1/results", serviceResultsHandler)
http.HandleFunc("/health", healthHandler)
http.Handle("/", http.FileServer(http.Dir("./static")))
if config.Get().Metrics {
if cfg.Metrics {
http.Handle("/metrics", promhttp.Handler())
}
log.Println("[main][main] Listening on port 8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}
func loadConfiguration() *config.Config {
args := os.Args
var err error
if len(args) == 2 {
err = config.Load(args[1])
} else {
err = config.LoadDefaultConfiguration()
}
if err != nil {
panic(err)
}
return config.Get()
}
func serviceResultsHandler(writer http.ResponseWriter, _ *http.Request) {
serviceResults := watchdog.GetServiceResults()
writer.WriteHeader(http.StatusOK)