Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
40 lines (33 sloc) 748 Bytes
// Seriál "Programovací jazyk Go"
//
// Dvanáctá část
//
// Demonstrační příklad číslo 7:
// Základní použití šablon
package main
import (
"fmt"
"html/template"
"net/http"
)
type IndexPageDynContent struct {
Title string
Header string
}
func mainEndpoint(writer http.ResponseWriter, request *http.Request) {
t, err := template.ParseFiles("index_template.html")
if err != nil {
writer.WriteHeader(http.StatusNotFound)
fmt.Fprint(writer, "Not found!")
return
}
dynData := IndexPageDynContent{Title: "Test", Header: "Welcome!"}
err = t.Execute(writer, dynData)
if err != nil {
println("Error executing template")
}
}
func main() {
http.HandleFunc("/", mainEndpoint)
http.ListenAndServe(":8000", nil)
}
You can’t perform that action at this time.