Skip to content

Instantly share code, notes, and snippets.

@hirokazumiyaji
Last active September 20, 2015 08:28
Show Gist options
  • Save hirokazumiyaji/8bcad55162cd7e828cd8 to your computer and use it in GitHub Desktop.
Save hirokazumiyaji/8bcad55162cd7e828cd8 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>{{.Title}}</title>
</head>
<body>
<div>
Hello {{.UserName}}.
</div>
</body>
</html>
package main
import (
"fmt"
"html/template"
"net/http"
)
var t *template.Template
func init() {
t, err = template.ParseFiles("index.html")
if err != nil {
panic(err)
}
}
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
data := struct{
Title string
UserName string
}{
Title: "Index Page",
UserName: r.URL.Query().Get("username"),
}
if err := t.Execute(w, data); err != nil {
panic(err)
}
})
http.ListenAndServe(":8000", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment