-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
61 lines (53 loc) · 1.13 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
package main
import (
"fmt"
"internal/cpu"
"io/ioutil"
"log"
"net/http"
"os"
"strconv"
"strings"
)
func handler(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/" {
http.Error(w, "404 not found.", http.StatusNotFound)
return
}
if r.URL.Path == "/cpu/temp" {
raw1, err := ioutil.ReadFile(os.Getenv("cpu_temp_path"))
raw2 := string(raw1)
raw3 := strings.ReplaceAll(raw2, "\n", "")
raw4, err := strconv.ParseFloat(string(raw3), 64)
raw5 := raw4 * 0.001
result := fmt.Sprintf("%v", raw5)
if err != nil {
http.Error(w, "500 Internal server error", http.StatusInternalServerError)
return
}
fmt.Fprintf(w, result)
}
if r.URL.Path == "/cpu/freq" {
}
if r.URL.Path == "/cpu/model" {
result := cpu.Name()
fmt.Fprintf(w, result)
}
if r.URL.Path == "/uptime" {
}
if r.URL.Path == "/mem/free" {
}
if r.URL.Path == "/mem/available" {
}
if r.Method != "GET" {
http.Error(w, "Method is not supported.", http.StatusNotFound)
return
}
}
func main() {
os.Setenv("cpu_temp_path", "")
http.HandleFunc("/", handler)
if err := http.ListenAndServe(":8080", nil); err != nil {
log.Fatal(err)
}
}