-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathmain.go
46 lines (37 loc) · 934 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
42
43
44
45
46
package main
import (
"fmt"
"html/template"
"net/http"
"os"
"time"
)
type Welcome struct {
Name string
Time string
Pod string
}
func getPort() string {
p := os.Getenv("APP_PORT")
if p != "" {
return ":" + p
}
return ":8080"
}
func main() {
welcome := Welcome{"GITOPS-K8S", time.Now().Format(time.Stamp), os.Getenv("HOSTNAME")}
templates := template.Must(template.ParseFiles("templates/welcome-template.html"))
http.Handle("/static/",
http.StripPrefix("/static/",
http.FileServer(http.Dir("static"))))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if name := r.FormValue("name"); name != "" {
welcome.Name = name
}
if err := templates.ExecuteTemplate(w, "welcome-template.html", welcome); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
})
fmt.Println("Listening on port " + getPort())
fmt.Println(http.ListenAndServe(getPort(), nil))
}