func init() { views = template.New("views") // Built-in views funcs views.Funcs(template.FuncMap{ "html": viewsFuncHTML, "nl2br": viewsFuncNL2BR, }) core.BeforeRun(func() { if _, err := os.Stat(viewsDir); err == nil { err = filepath.Walk(viewsDir, func(path string, f os.FileInfo, err error) error { if err != nil { return err } if !f.IsDir() { if _, err = views.ParseFiles(path); err != nil { return err } } return nil }) if err != nil { panic(err) } } }) }
// Use adds the handler to the default handlers stack. // It prints each request/response information (time, duration, status, method, path). func Use() { core.BeforeRun(func() { fmt.Printf("%s%s Server running on %s%s%s %s %s\n\n", colors.ResetAll, colors.Reverse, colors.ResetAll, colors.BackgroundMagenta, colors.White, core.Address, colors.ResetAll) }) core.Use(func(c *core.Context) { start := time.Now() path := c.Request.URL.Path // Keep original request path in case of http.StripPrefix. defer func() { log.Printf(" %s %s %s %s", fmtDuration(start), fmtStatus(c), fmtMethod(c), fmtPath(path)) }() defer c.Recover() c.Next() }) }
func init() { if _, err := os.Stat(templatesDir); err != nil { return } templates = template.New(templatesDir) // Built-in templates funcs templates.Funcs(template.FuncMap{ "html": templatesFuncHTML, "nl2br": templatesFuncNL2BR, }) core.BeforeRun(func() { if err := filepath.Walk(templatesDir, templatesWalk); err != nil { panic("response: " + err.Error()) } }) }