Created
September 11, 2016 03:16
-
-
Save asit-dhal/94e711eec5e54e97e9b8e35038c0182d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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