-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
54 lines (44 loc) · 1.02 KB
/
main.go
File metadata and controls
54 lines (44 loc) · 1.02 KB
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
package main
import (
"html/template"
"log"
"net/http"
"os"
"runtime"
)
type osData struct {
Hostname string
OS string
Architecture string
CPUs int
GoVersion string
}
func httpHandler(w http.ResponseWriter, r *http.Request) {
hostname, err := os.Hostname()
if err != nil {
hostname = "unknown"
}
var data = osData{
Hostname: hostname,
OS: runtime.GOOS,
Architecture: runtime.GOARCH,
CPUs: runtime.NumCPU(),
GoVersion: runtime.Version(),
}
// Parse the template file
tmpl := template.Must(template.ParseFiles("layout.html"))
// Execute the template, writing the output to the http.ResponseWriter
tmpl.Execute(w, data)
w.Header().Set("content-type", "text/html")
}
func main() {
var port = os.Getenv("PORT")
if port == "" {
port = "8000"
}
http.HandleFunc("/", httpHandler)
log.Println("Server started on :" + port)
log.Println("Visit http://localhost:" + port)
log.Println("Press Ctrl+C to stop the server")
http.ListenAndServe(":"+port, nil)
}