main.go 618 B

1234567891011121314151617181920212223242526272829303132
  1. package main
  2. import (
  3. "fmt"
  4. "html/template"
  5. "net/http"
  6. "time"
  7. "github.com/gin-gonic/gin"
  8. )
  9. func formatAsDate(t time.Time) string {
  10. year, month, day := t.Date()
  11. return fmt.Sprintf("%d%02d/%02d", year, month, day)
  12. }
  13. func main() {
  14. router := gin.Default()
  15. router.Delims("{[{", "}]}")
  16. router.SetFuncMap(template.FuncMap{
  17. "formatAsDate": formatAsDate,
  18. })
  19. router.LoadHTMLFiles("../../testdata/template/raw.tmpl")
  20. router.GET("/raw", func(c *gin.Context) {
  21. c.HTML(http.StatusOK, "raw.tmpl", map[string]interface{}{
  22. "now": time.Date(2017, 07, 01, 0, 0, 0, 0, time.UTC),
  23. })
  24. })
  25. router.Run(":8080")
  26. }