...
Source file
src/discovery/discovery.go
1
18
19
20 package main
21
22 import (
23 "discovery/api"
24 "discovery/config"
25 "discovery/db"
26 "discovery/log"
27 "discovery/watcher"
28 "fmt"
29 "github.com/gorilla/mux"
30 "net/http"
31 "sync"
32 )
33
34 var wg sync.WaitGroup
35
36 func main() {
37
38 config.Start()
39 db.Start()
40
41 wg.Add(2)
42 go server()
43 go watchd()
44
45 log.Log.Infof("Discovery server started successfully")
46
47 wg.Wait()
48 }
49
50 func server() {
51
52
53
54
55 router := mux.NewRouter()
56 router.HandleFunc("/", api.Hello).Methods("GET")
57 router.HandleFunc("/list", api.ServersGetList).Methods("GET")
58 router.HandleFunc("/reset", api.ServersReset).Methods("GET")
59
60
61
62 router.HandleFunc("/configuration", api.ConfigurationGet).Methods("GET")
63 router.HandleFunc("/configuration", api.ConfigurationSet).Methods("POST")
64
65
66 server := &http.Server{
67 Addr: fmt.Sprintf("%s:%d", config.GetListeningHost(), config.GetListeningPort()),
68 Handler: router,
69 }
70
71 log.Log.Infof("Started listening on %s:%d", config.GetListeningHost(), config.GetListeningPort())
72 err := server.ListenAndServe()
73
74 log.Log.Fatalf("Error while starting server: %s", err)
75 wg.Done()
76 }
77
78 func watchd() {
79 log.Log.Infof("Watcher started")
80 watcher.PollingLooper()
81 wg.Done()
82 }
83
View as plain text