Serving template from go handler function

This commit is contained in:
Beto
2024-02-24 21:51:34 -06:00
parent 0cf7052b5d
commit 6144cef1a2
4 changed files with 45 additions and 3 deletions

View File

@@ -2,17 +2,17 @@ package main
import (
"fmt"
"io"
"log"
"net/http"
"text/template"
)
func main() {
fmt.Println("hello world")
h1 := func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "Hello World\n")
//io.WriteString(w, r.Method)
tmpl := template.Must(template.ParseFiles("index.html"))
tmpl.Execute(w, nil)
}
http.HandleFunc("/", h1)