-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
41 lines (35 loc) · 782 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
37
38
39
40
41
package main
import (
"encoding/json"
"net/http"
"syscall"
)
func stringify(f [65]int8) string {
out := make([]byte, 0, 64)
for _, v := range f[:] {
if v == 0 {
break
}
out = append(out, uint8(v))
}
return string(out)
}
func getSystemInfo() map[string]string {
var uname syscall.Utsname
if err := syscall.Uname(&uname); err != nil {
panic(err)
}
m := make(map[string]string)
m["message"] = "Hello, there!"
m["os"] = stringify(uname.Sysname) + " " + stringify(uname.Release)
m["arch"] = stringify(uname.Machine)
return m
}
func helloHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(getSystemInfo())
}
func main() {
http.HandleFunc("/hello", helloHandler)
http.ListenAndServe(":8080", nil)
}