Skip to content

Instantly share code, notes, and snippets.

@mmirolim
Created December 27, 2014 17:55
Show Gist options
  • Select an option

  • Save mmirolim/ee4130b75b1557c91c78 to your computer and use it in GitHub Desktop.

Select an option

Save mmirolim/ee4130b75b1557c91c78 to your computer and use it in GitHub Desktop.
package main
import (
"html/template"
"log"
"net/http"
"time"
)
func main() {
http.HandleFunc("/show", Show)
log.Fatal(http.ListenAndServe(":3000", nil))
}
func Show(w http.ResponseWriter, r *http.Request) {
now := time.Now()
t, err := template.New("foo").Parse(`{{define "T"}}Time, {{.}}!{{end}}`)
err = t.ExecuteTemplate(w, "T", now)
if err != nil {
log.Fatalln(err)
}
}
// outputs -> Time, 2014-12-27 22:53:17.638884509 +0500 UZT!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment