Last active
September 20, 2015 08:28
-
-
Save hirokazumiyaji/8bcad55162cd7e828cd8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>{{.Title}}</title> | |
</head> | |
<body> | |
<div> | |
Hello {{.UserName}}. | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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