-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
36 lines (28 loc) · 817 Bytes
/
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
package main
import (
"fmt"
"log"
"net/http"
"sync"
"github.com/awildboop/sysapi/handlers"
"github.com/gorilla/mux"
)
func main() {
config, err := initConfiguration()
if err != nil {
log.Fatal("Unable to load configuration.")
}
r := mux.NewRouter()
r.HandleFunc("/api/stats/cpu", handlers.CPUHandler).Methods("GET")
r.HandleFunc("/api/stats/mem", handlers.MemHandler).Methods("GET")
r.HandleFunc("/api/stats/sys", handlers.SystemStats).Methods("GET")
r.HandleFunc("/api/stats/all", handlers.SystemStats).Methods("GET")
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
http.ListenAndServe(fmt.Sprintf("%s:%s", config.Connection.Host, config.Connection.Port), r)
}()
fmt.Printf("Now listening at %s on port %s\n", config.Connection.Host, config.Connection.Port)
wg.Wait()
}