Skip to content

Instantly share code, notes, and snippets.

@asit-dhal
Created September 11, 2016 03:16
Show Gist options
  • Save asit-dhal/94e711eec5e54e97e9b8e35038c0182d to your computer and use it in GitHub Desktop.
Save asit-dhal/94e711eec5e54e97e9b8e35038c0182d to your computer and use it in GitHub Desktop.
package main
import (
"html/template"
"net/http"
)
var tmpl = `<html>
<head>
<title>Hello World!</title>
</head>
<body>
{{ . }}
</body>
</html>
`
func handler(w http.ResponseWriter, r *http.Request) {
t := template.New("main") //name of the template is main
t, _ = t.Parse(tmpl) // parsing of template string
t.Execute(w, "Hello World!")
}
func main() {
server := http.Server{
Addr: "127.0.0.1:8080",
}
http.HandleFunc("/view", handler)
server.ListenAndServe()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment