init repo

This commit is contained in:
James Newman
2024-06-12 12:44:00 +01:00
commit 96b4c8f931
7 changed files with 145 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
package main
import (
"html/template"
"log"
"net/http"
"strings"
)
func main() {
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(":8080", nil))
}
func handler(w http.ResponseWriter, r *http.Request) {
name := strings.Replace(r.URL.Path, "/", "", 1)
if name == "" {
name = "World"
}
t, err := template.ParseFiles("index.html")
if err != nil {
log.Fatal("error parsing template: ", err)
}
err = t.Execute(w, name)
if err != nil {
log.Fatal("error executing template: ", err)
}
}