2017-07-21 02:29:23 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"html/template"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
func formatAsDate(t time.Time) string {
|
|
|
|
year, month, day := t.Date()
|
|
|
|
return fmt.Sprintf("%d%02d/%02d", year, month, day)
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
router := gin.Default()
|
|
|
|
router.Delims("{[{", "}]}")
|
|
|
|
router.SetFuncMap(template.FuncMap{
|
|
|
|
"formatAsDate": formatAsDate,
|
|
|
|
})
|
2018-08-12 15:38:31 +00:00
|
|
|
router.LoadHTMLFiles("../../testdata/template/raw.tmpl")
|
2017-07-21 02:29:23 +00:00
|
|
|
|
|
|
|
router.GET("/raw", func(c *gin.Context) {
|
|
|
|
c.HTML(http.StatusOK, "raw.tmpl", map[string]interface{}{
|
|
|
|
"now": time.Date(2017, 07, 01, 0, 0, 0, 0, time.UTC),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
router.Run(":8080")
|
|
|
|
}
|