Skip to content

Instantly share code, notes, and snippets.

@codenoid
Last active October 6, 2019 05:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codenoid/2712fc88711a59b2b84d5f40d3b8d48d to your computer and use it in GitHub Desktop.
Save codenoid/2712fc88711a59b2b84d5f40d3b8d48d to your computer and use it in GitHub Desktop.
golang net/http template usage
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