diff --git a/clicked.go b/clicked.go new file mode 100644 index 0000000..961d25a --- /dev/null +++ b/clicked.go @@ -0,0 +1,10 @@ +package main + +import ( + "fmt" + "net/http" +) + +func handleClicked(w http.ResponseWriter, r *http.Request) { + fmt.Fprint(w, "Clicked") +} diff --git a/index.go b/index.go new file mode 100644 index 0000000..de0df7f --- /dev/null +++ b/index.go @@ -0,0 +1,34 @@ +package main + +import ( + "html/template" + "net/http" + "time" +) + +var index_template *template.Template + +type indexData struct { + Time string +} + +func handleRoot(w http.ResponseWriter, r *http.Request) { + //if index_template == nil { + // tmpl, err := template.ParseFiles("templates/index.html") + // if err != nil { + // http.Error(w, "Couldn't parse template file", http.StatusInternalServerError) + // return + // } + // index_template = tmpl + //} + + tmpl, err := template.ParseFiles("templates/index.html") + if err != nil { + http.Error(w, "Couldn't parse template file", http.StatusInternalServerError) + return + } + err = tmpl.Execute(w, indexData{Time: time.Now().Format(time.Stamp)}) + if err != nil { + http.Error(w, "Failed to execute template", http.StatusInternalServerError) + } +} diff --git a/main.go b/main.go index e8bff16..394fde9 100644 --- a/main.go +++ b/main.go @@ -1,12 +1,22 @@ package main -import "net/http" +import ( + "log" + "net/http" + "os" +) func main() { + port := os.Getenv("PORT") + if port == "" { + port = "8080" + log.Printf("Defaulting to port %s \n", port) + } + http.HandleFunc("/", handleRoot) - http.ListenAndServe("0.0.0.0:8000", nil) -} - -func handleRoot(w http.ResponseWriter, r *http.Request) { + http.HandleFunc("/clicked", handleClicked) + if err := http.ListenAndServe(":"+port, nil); err != nil { + log.Fatal(err) + } } diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..a7cd2cd --- /dev/null +++ b/templates/index.html @@ -0,0 +1,19 @@ + + +
+ + + +This webpage is still under construction
+Evilthings will be the studio name under which mStar will release software
+ + \ No newline at end of file