-
Notifications
You must be signed in to change notification settings - Fork 8
/
simple_status.go
55 lines (48 loc) · 1.28 KB
/
simple_status.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
package main
import (
"flag"
"log"
"net/http"
"strconv"
)
var token *string
func toInt(b []byte) (i int) {
i, err := strconv.Atoi(string(b))
if err != nil {
log.Println("Failed to convert string to int")
}
return
}
func toFloat(b []byte) (f float64) {
f, err := strconv.ParseFloat(string(b), 64)
if err != nil {
log.Println("Failed to convert string to float")
}
return
}
func main() {
port := flag.String("p", ":8080", "http service address")
token = flag.String("t", "", "http auth token")
tls := flag.Bool("ssl", false, "TLS boolean flag")
flag.Parse()
base := "/1/api"
http.HandleFunc(base+"/system", makeHandler(systemHandler))
http.HandleFunc(base+"/system/ram", makeHandler(ramHandler))
http.HandleFunc(base+"/system/load", makeHandler(loadHandler))
http.HandleFunc(base+"/system/host", makeHandler(hostHandler))
http.HandleFunc(base+"/system/disk", makeHandler(diskHandler))
http.HandleFunc(base+"/system/cpuinfo", makeHandler(cpuHandler))
http.HandleFunc(base+"/shell", makeHandler(shellHandler))
switch *tls {
case false:
err := http.ListenAndServe(*port, nil)
if err != nil {
log.Fatal("ListenAndServe:", err)
}
case true:
err := http.ListenAndServeTLS(*port, "cert.pem", "key.pem", nil)
if err != nil {
log.Fatal("ListenAndServeTLS:", err)
}
}
}