Merge "Add SRIOV and QAT device plugin deploy components" into dev/icn-v0.1.0
[icn.git] / cmd / bpa-restapi-agent / main.go
1 // main.go
2 package main
3
4 import (
5   "context"
6   "log"
7   "math/rand"
8   "net/http"
9   "os"
10   "os/signal"
11   "time"
12
13   //To Do - Implement internal for checking config
14   "github.com/gorilla/handlers"
15
16   "bpa-restapi-agent/api"
17   utils "bpa-restapi-agent/internal"
18   "bpa-restapi-agent/internal/config"
19 )
20
21 func main() {
22   // To Do - Implement initial settings
23   // check initial config
24   err := utils.CheckInitialSettings()
25   if err != nil{
26     log.Fatal(err)
27   }
28
29   rand.Seed(time.Now().UnixNano())
30
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")
35
36   // Create custom http server
37   httpServer := &http.Server{
38     Handler: loggedRouter,
39     // To Do - Implement config
40     Addr:    ":" + config.GetConfiguration().ServicePort,
41   }
42   connectionsClose := make(chan struct{})
43   go func() {
44     c := make(chan os.Signal, 1) // create c channel to receive notifications
45     signal.Notify(c, os.Interrupt) // register c channel to run concurrently
46     <-c
47     httpServer.Shutdown(context.Background())
48     close(connectionsClose)
49   }()
50
51   // Start server
52   log.Fatal(httpServer.ListenAndServe())
53
54 }