-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
71 lines (60 loc) · 1.45 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
62
63
64
65
66
67
68
69
70
71
package main
import (
"html/template"
"log"
"net/http"
"os"
_ "github.com/DTherHtun/k8smm-weblab/statik"
"github.com/rakyll/statik/fs"
)
//Info is info
type Info struct {
Title string
Done string
}
//InfoPageData is data
type InfoPageData struct {
Color string
PageTitle string
Infos []Info
}
func main() {
hostName, err := os.Hostname()
if err != nil {
panic(err)
}
statikFS, err := fs.New()
if err != nil {
log.Fatal(err)
}
fs := http.FileServer(statikFS)
http.Handle("/static/", http.StripPrefix("/static/", fs))
color := getEnv("COLOR", "powderblue")
pgtitle := getEnv("PG_TITLE", "K8s User Group Myanmar!")
tmpl := template.Must(template.ParseFiles("/go/bin/index.html"))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
data := InfoPageData{
Color: color,
PageTitle: pgtitle,
Infos: []Info{
{Title: "Pod Name - ", Done: hostName},
{Title: "Host - ", Done: r.Host},
{Title: "Remote Address - ", Done: r.RemoteAddr},
{Title: "Request Method - ", Done: r.Method},
{Title: "Request URL - ", Done: r.URL.String()},
{Title: "Protocol - ", Done: r.Proto},
{Title: "UserAgent - ", Done: r.UserAgent()},
},
}
tmpl.Execute(w, data)
log.Printf("--> %s %s 200", r.Method, r.URL.Path)
})
log.Fatal(http.ListenAndServe(":8080", nil))
}
func getEnv(key, defaultValue string) string {
value := os.Getenv(key)
if len(value) == 0 {
return defaultValue
}
return value
}