Skip to content
Permalink
Browse files

02-Template add simple text template

  • Loading branch information...
bonfy committed Sep 6, 2018
1 parent 483e26c commit 1cf55f62ae8ee34bb9fec64508398480b9168e2c
Showing with 19 additions and 2 deletions.
  1. +19 −2 main.go
21 main.go
@@ -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.
You can’t perform that action at this time.