-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
38 lines (33 loc) · 895 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
package main
import (
"fmt"
"html/template"
"log"
"net/http"
"time"
)
//Website struct information
type Website struct {
Name string
Time string
}
func main() {
website := Website{"Mitch", time.Now().Format(time.Stamp)}
templates := template.Must(template.ParseFiles("templates/website-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 != "" {
website.Name = name
}
if err := templates.ExecuteTemplate(w, "website-template.html", website); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
t1 := time.Now()
t2 := time.Now()
log.Printf("[%s] %q %v\n", r.Method, r.URL.String(), t2.Sub(t1))
})
fmt.Println("Listening")
fmt.Println(http.ListenAndServe(":8080", nil))
}