Skip to content

Commit

Permalink
02-Template add simple text template
Browse files Browse the repository at this point in the history
  • Loading branch information
bonfy committed Sep 6, 2018
1 parent 483e26c commit 1cf55f6
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
package main

import "net/http"
import (
"html/template"
"net/http"
)

// User struct
type User struct {
Username string
}

func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello World"))
user := User{Username: "bonfy"}
tpl, _ := template.New("").Parse(`<html>
<head>
<title>Home Page - Bonfy</title>
</head>
<body>
<h1>Hello, {{.Username}}!</h1>
</body>
</html>`)
tpl.Execute(w, &user)
})
http.ListenAndServe(":8888", nil)
}

0 comments on commit 1cf55f6

Please sign in to comment.