14 "github.com/gorilla/handlers"
16 "bpa-restapi-agent/api"
17 utils "bpa-restapi-agent/internal"
18 "bpa-restapi-agent/internal/auth"
19 "bpa-restapi-agent/internal/config"
23 // check initial config
24 err := utils.CheckInitialSettings()
29 rand.Seed(time.Now().UnixNano())
31 httpRouter := api.NewRouter(nil, nil, nil)
32 // Return http.handler and log requests to Stdout
33 loggedRouter := handlers.LoggingHandler(os.Stdout, httpRouter)
34 log.Println("Starting Integrated Cloud Native API")
36 // Create custom http server
37 httpServer := &http.Server{
38 Handler: loggedRouter,
39 Addr: ":" + config.GetConfiguration().ServicePort,
41 connectionsClose := make(chan struct{})
43 c := make(chan os.Signal, 1) // create c channel to receive notifications
44 signal.Notify(c, os.Interrupt) // register c channel to run concurrently
46 httpServer.Shutdown(context.Background())
47 close(connectionsClose)
51 tlsConfig, err := auth.GetTLSConfig("ca.cert", "server.cert", "server.key")
53 log.Println("Error Getting TLS Configuration. Starting without TLS...")
54 log.Fatal(httpServer.ListenAndServe())
56 httpServer.TLSConfig = tlsConfig
57 // empty strings because tlsconfig already has this information
58 err = httpServer.ListenAndServeTLS("", "")