-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
67 lines (53 loc) · 1.37 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
package main
import (
"flag"
"log"
"github.com/gorilla/mux"
"github.com/sevlyar/go-daemon"
"net/http"
"github.com/sunshine69/nagios-api-go/controllers"
"github.com/sunshine69/nagios-api-go/conf"
)
func main() {
Forking := flag.Bool("d", false, "Forking as deamon. Need to look into the config.json to set the log file and pid path correctly")
flag.Parse()
if *Forking {
cntxt := &daemon.Context{
PidFileName: conf.Config.PidFilePath,
PidFilePerm: 0644,
LogFileName: conf.Config.LogFilePath,
LogFilePerm: 0640,
WorkDir: "./",
Umask: 027,
Args: []string{"[go-daemon nagios-api]"},
}
d, err := cntxt.Reborn()
if err != nil {
log.Fatal("Unable to run: ", err)
}
if d != nil {
return
}
defer cntxt.Release()
log.Print("- - - - - - - - - - - - - - -")
log.Print("daemon started")
serveHTTP()
} else {
serveHTTP()
}
}
func serveHTTP() {
router := mux.NewRouter()
router.HandleFunc("/{nagios_host}/service/{service_name}", controllers.GetServiceStatus).Methods("GET")
// router.Use(app.JwtAuthentication) //attach JWT auth middleware
//router.NotFoundHandler = app.NotFoundHandler
port := conf.Config.Port
if port == "" {
port = "8000" //localhost
}
log.Printf("Port: %v\n", port)
err := http.ListenAndServe(":"+port, router) //Launch the app, visit localhost:8000/api
if err != nil {
log.Println(err)
}
}