-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
73 lines (56 loc) · 1.67 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"fmt"
"net/http"
figure "github.com/common-nighthawk/go-figure"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
log "github.com/sirupsen/logrus"
"github.com/specialedge/hangar-api/api/healthcheck"
"github.com/specialedge/hangar-api/api/java"
"github.com/spf13/viper"
)
func main() {
//log.SetLevel(log.DebugLevel)
// Create startup message to welcome the user.
startUpMessage := figure.NewFigure("hangar-api", "smslant", true)
startUpMessage.Print()
// Print event to show the system is starting
log.WithFields(log.Fields{
"module": "main",
"action": "PrintStartUpMessage",
}).Info("Starting")
// Read in the configuration file
readConfiguration()
// Create a router and admin & service endpoints
r := mux.NewRouter()
r.HandleFunc("/healthcheck", healthcheck.HandlerHealthcheck)
// Initialise the repo endpoints
if viper.IsSet("java") {
java.InitialiseJavaEndpoints(r)
log.WithFields(log.Fields{
"module": "main",
"action": "JavaEnabled",
}).Info("Finished creating Java Endpoint")
}
// Serve on 8080 with CORS support.
http.ListenAndServe(":8080", handlers.CORS()(r))
}
func readConfiguration() {
// Without a configuration file, we don't want to start the system.
viper.SetConfigName("config")
viper.AddConfigPath(".")
viper.AddConfigPath("./config")
err := viper.ReadInConfig()
if err != nil {
log.WithFields(log.Fields{
"module": "main",
"action": "readConfiguration",
}).Info("Failed to read configuration file : %s", err)
panic(fmt.Errorf("Fatal error config file: %s", err))
}
log.WithFields(log.Fields{
"module": "main",
"action": "readConfiguration",
}).Info("Configuration parsed...")
}