Skip to content

Instantly share code, notes, and snippets.

@asit-dhal
Created September 11, 2016 03:19
Show Gist options
  • Save asit-dhal/cf74c1bc83745e0141e565fee31c5f09 to your computer and use it in GitHub Desktop.
Save asit-dhal/cf74c1bc83745e0141e565fee31c5f09 to your computer and use it in GitHub Desktop.
package main
import (
"net/http"
"html/template"
)
func handler1(w http.ResponseWriter, r *http.Request) {
t, _ := template.ParseFiles("t1.html", "t2.html")
t.Execute(w, "Asit")
}
func handler2(w http.ResponseWriter, r *http.Request) {
t, _ := template.ParseFiles("t1.html", "t2.html")
t.ExecuteTemplate(w, "t2.html", "Golang")
}
func main() {
server := http.Server{
Addr: "127.0.0.1:8080",
}
http.HandleFunc("/t1", handler1)
http.HandleFunc("/t2", handler2)
server.ListenAndServe()
}
<html>
<head>
<title>T1 template</title>
</head>
<body>
Hi, My name is {{ . }}.
</body>
</html>
<html>
<head>
<title>T2 template</title>
</head>
<body>
Hi, I am learning {{ . }}.
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment