-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (37 loc) · 1.11 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"flag"
"github.com/go-chi/chi/v5"
"github.com/gorilla/handlers"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
"net/http"
"os"
)
func init() {
flag.StringVar(&ConfigFile, "file", "", "Path to config file")
if ConfigFile == "" {
log.Fatal("Config file not specified, use default")
f, _ := os.Create("config.ini")
f.WriteString(DefaultConfig)
}
}
func main() {
route := chi.NewMux()
config := loadIni()
route.Handle("/", handlers.LoggingHandler(os.Stdout, config.NewWebReverseProxy()))
route.Handle("/metrics", promhttp.Handler())
log.Infof("Starting server on %s", config.HttpAddress)
// Start the server
switch {
case config.IsPrivate == true && config.UseTLS.Use == true:
if err := http.ListenAndServeTLS(config.HttpAddress, config.UseTLS.CertFile, config.UseTLS.KeyFile, route); err != nil {
log.Fatalf("Failed to start terraform registry proxy\nERR:%v", err)
}
default:
if err := http.ListenAndServe(config.HttpAddress, route); err != nil {
log.Fatalf("Failed to start terraform registry proxy\nERR:%v", err)
}
}
recover()
}