Skip to content

Commit

Permalink
02-Template add templates folder
Browse files Browse the repository at this point in the history
  • Loading branch information
bonfy committed Sep 7, 2018
1 parent 1cf55f6 commit cca162a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 1 addition & 8 deletions main.go
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@ type User struct {
func main() { func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
user := User{Username: "bonfy"} user := User{Username: "bonfy"}
tpl, _ := template.New("").Parse(`<html> tpl, _ := template.ParseFiles("templates/index.html")
<head>
<title>Home Page - Bonfy</title>
</head>
<body>
<h1>Hello, {{.Username}}!</h1>
</body>
</html>`)
tpl.Execute(w, &user) tpl.Execute(w, &user)
}) })
http.ListenAndServe(":8888", nil) http.ListenAndServe(":8888", nil)
Expand Down
8 changes: 8 additions & 0 deletions templates/index.html
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title>Home Page - Bonfy</title>
</head>
<body>
<h1>Hello, {{.Username}}!</h1>
</body>
</html>

0 comments on commit cca162a

Please sign in to comment.