Serving template from go handler function
This commit is contained in:
6
main.go
6
main.go
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user