Last active
October 6, 2019 05:48
-
-
Save codenoid/2712fc88711a59b2b84d5f40d3b8d48d to your computer and use it in GitHub Desktop.
golang net/http template usage
This file contains hidden or 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 ( | |
"fmt" | |
"net/http" | |
) | |
func index(w http.ResponseWriter, r *http.Request) { | |
w.WriteHeader(200) | |
tmpl := template.Must(template.ParseFiles("path/to/template.html")) | |
tmpl.Execute(w, nil) | |
} | |
func main() { | |
http.HandleFunc("/", index) | |
fmt.Println("Starting server at port 3000 ...") | |
http.ListenAndServe("127.0.0.1:3000", nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment