本文整理汇总了Golang中github.com/Unknwon/macaron.Renderer函数的典型用法代码示例。如果您正苦于以下问题:Golang Renderer函数的具体用法?Golang Renderer怎么用?Golang Renderer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Renderer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: middlewareScenario
func middlewareScenario(desc string, fn scenarioFunc) {
Convey(desc, func() {
defer bus.ClearBusHandlers()
sc := &scenarioContext{}
viewsPath, _ := filepath.Abs("../../public/views")
sc.m = macaron.New()
sc.m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: viewsPath,
Delims: macaron.Delims{Left: "[[", Right: "]]"},
}))
sc.m.Use(GetContextHandler())
// mock out gc goroutine
startSessionGC = func() {}
sc.m.Use(Sessioner(&session.Options{}))
sc.defaultHandler = func(c *Context) {
sc.context = c
if sc.handlerFunc != nil {
sc.handlerFunc(sc.context)
}
}
sc.m.Get("/", sc.defaultHandler)
fn(sc)
})
}
示例2: main
func main() {
// flag.Parse()
log.Info("App Version: %s", APP_VER)
var port string
if port = os.Getenv(PortVar); port == "" {
port = "8080"
}
log.Info("PORT: %s", port)
m := macaron.Classic()
m.Use(macaron.Renderer())
// m.Use(middleware.Contexter())
m.Get("/", func() string {
return "Hello"
})
m.Get("/fibonacci", v1.Fibonacci)
// log.Info("PORT: %s", setting.HTTPPort)
// _ = setting.HTTPPort
http.ListenAndServe(":"+port, m)
// http.ListenAndServe(fmt.Sprintf(":%d", *port), m)
// http.ListenAndServe(":"+setting.HTTPPort, m)
// m.Run(":" + setting.HTTPPort)
}
示例3: _StartMartini
func _StartMartini() {
WEB.Use(macaron.Recovery())
WEB.Use(macaron.Static("public",
macaron.StaticOptions{
FileSystem: bindata.Static(bindata.Options{
Asset: public.Asset,
AssetDir: public.AssetDir,
AssetNames: public.AssetNames,
Prefix: "",
}),
SkipLogging: true,
},
))
WEB.Use(macaron.Renderer(macaron.RenderOptions{
//Directory: "templates", //!!when package,escape this line. Specify what path to load the templates from.
Layout: "layout", // Specify a layout template. Layouts can call {{ yield }} to render the current template.
//Extensions: []string{".tmpl", ".html"}, //!!when package,escape this line. Specify extensions to load for templates.
//Charset: "UTF-8", //!!when package,escape this line. Sets encoding for json and html content-types. Default is "UTF-8".
TemplateFileSystem: bindata.Templates(bindata.Options{ //make templates files into bindata.
Asset: templates.Asset,
AssetDir: templates.AssetDir,
AssetNames: templates.AssetNames,
Prefix: ""}),
}))
LoadRoute()
WEB.Run(cfg.HOST, cfg.PORT)
}
示例4: newGitea
func newGitea() *macaron.Macaron {
m := macaron.Classic()
m.Use(macaron.Renderer(macaron.RenderOptions{
Funcs: []template.FuncMap{map[string]interface{}{
"dict": base.Dict,
"str2html": base.Str2html,
"appVersion": func() string {
return version
},
"appRev": func() string {
return revision
},
}},
}))
m.Use(i18n.I18n(i18n.Options{
Langs: setting.Langs,
Names: setting.Names,
Redirect: true,
}))
m.Get("/", routers.Home)
m.Get("/docs/images/:all", routers.Static)
m.Get("/docs", routers.Docs)
m.Get("/docs/*", routers.Docs)
m.Get("/about", routers.About)
m.Get("/team", routers.Team)
return m
}
示例5: main
func main() {
readConfig()
log.SetOutputLevel(log.Ldebug)
m.Use(macaron.Renderer())
m.Run(*srvPort)
}
示例6: newMacaron
func newMacaron() *macaron.Macaron {
macaron.Env = setting.Env
m := macaron.New()
m.Use(middleware.Logger())
m.Use(macaron.Recovery())
if setting.EnableGzip {
m.Use(middleware.Gziper())
}
mapStatic(m, "", "public")
mapStatic(m, "app", "app")
mapStatic(m, "css", "css")
mapStatic(m, "img", "img")
mapStatic(m, "fonts", "fonts")
mapStatic(m, "robots.txt", "robots.txt")
m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: path.Join(setting.StaticRootPath, "views"),
IndentJSON: macaron.Env != macaron.PROD,
Delims: macaron.Delims{Left: "[[", Right: "]]"},
}))
if setting.EnforceDomain {
m.Use(middleware.ValidateHostHeader(setting.Domain))
}
m.Use(middleware.GetContextHandler())
m.Use(middleware.Sessioner(&setting.SessionOptions))
return m
}
示例7: main
func main() {
// Set log options.
log.SetOutput(os.Stderr)
log.SetLevel(log.WarnLevel)
// Options.
var opts struct {
Verbose bool `short:"v" long:"verbose" description:"Verbose"`
Version bool `long:"version" description:"Version"`
BindAddr string `short:"b" long:"bind-addr" description:"Bind to address" default:"0.0.0.0"`
Port int `short:"p" long:"port" description:"Port" default:"5050"`
StaticDir string `short:"s" long:"static-dir" description:"Static content" default:"static"`
TemplateDir string `short:"t" long:"template-dir" description:"Templates" default:"templates"`
}
// Parse options.
if _, err := flags.Parse(&opts); err != nil {
ferr := err.(*flags.Error)
if ferr.Type == flags.ErrHelp {
os.Exit(0)
} else {
log.Fatal(err.Error())
}
}
// Print version.
if opts.Version {
fmt.Printf("peekaboo %s\n", Version)
os.Exit(0)
}
// Set verbose.
if opts.Verbose {
log.SetLevel(log.InfoLevel)
}
// Check root.
if runtime.GOOS != "darwin" && os.Getuid() != 0 {
log.Fatal("This application requires root privileges to run.")
}
info, err := hwinfo.Get()
if err != nil {
log.Fatal(err.Error())
}
log.Infof("Using static dir: %s", opts.StaticDir)
log.Infof("Using template dir: %s", opts.TemplateDir)
m := macaron.Classic()
m.Use(macaron.Static(opts.StaticDir))
m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: opts.TemplateDir,
IndentJSON: true,
}))
routes(m, info)
m.Run(opts.BindAddr, opts.Port)
}
示例8: main
func main() {
log.Info("App Version: %s", APP_VER)
m := macaron.Classic()
m.Use(macaron.Renderer())
m.Use(middleware.Contexter())
m.Get("/fibonacci", v1.Fibonacci)
m.Run(setting.HTTPPort)
}
示例9: newMacaron
// newMacaron initializes Macaron instance.
func newMacaron() *macaron.Macaron {
m := macaron.New()
m.Use(macaron.Logger())
m.Use(macaron.Recovery())
if setting.EnableGzip {
m.Use(macaron.Gziper())
}
m.Use(macaron.Static(
path.Join(setting.StaticRootPath, "public"),
macaron.StaticOptions{
SkipLogging: !setting.DisableRouterLog,
},
))
m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: path.Join(setting.StaticRootPath, "templates"),
Funcs: []template.FuncMap{base.TemplateFuncs},
IndentJSON: macaron.Env != macaron.PROD,
}))
m.Use(i18n.I18n(i18n.Options{
SubURL: setting.AppSubUrl,
Directory: path.Join(setting.ConfRootPath, "locale"),
CustomDirectory: path.Join(setting.CustomPath, "conf/locale"),
Langs: setting.Langs,
Names: setting.Names,
Redirect: true,
}))
m.Use(cache.Cacher(cache.Options{
Adapter: setting.CacheAdapter,
Interval: setting.CacheInternal,
Conn: setting.CacheConn,
}))
m.Use(captcha.Captchaer(captcha.Options{
SubURL: setting.AppSubUrl,
}))
m.Use(session.Sessioner(session.Options{
Provider: setting.SessionProvider,
Config: *setting.SessionConfig,
}))
m.Use(csrf.Generate(csrf.Options{
Secret: setting.SecretKey,
SetCookie: true,
Header: "X-Csrf-Token",
CookiePath: setting.AppSubUrl,
}))
m.Use(toolbox.Toolboxer(m, toolbox.Options{
HealthCheckFuncs: []*toolbox.HealthCheckFuncDesc{
&toolbox.HealthCheckFuncDesc{
Desc: "Database connection",
Func: models.Ping,
},
},
}))
m.Use(middleware.Contexter())
return m
}
示例10: main
func main() {
server_root := "https://nicksite.com:3000"
local_login_url := "http://nicksite.com:4000/login"
m := macaron.Classic()
m.Use(macaron.Renderer())
m.Use(session.Sessioner())
m.Get("/login", func(ctx *macaron.Context, s session.Store) {
ticket := ctx.Query("ticket")
if len(ticket) == 0 {
ctx.Redirect(server_root + "/login?service=" + local_login_url)
return
} else {
s.Set("ticket", ticket)
ctx.Redirect("/")
}
})
m.Get("/", func(ctx *macaron.Context, s session.Store) string {
if s.Get("login") != nil {
return "Welcome, " + s.Get("login").(string)
}
// Retrieve the ticket
if s.Get("ticket") == nil {
ctx.Redirect("/login")
return ""
}
// Validate the ticket
ticket := s.Get("ticket").(string)
resp, err := http.Get(server_root + "/validate?ticket=" + ticket + "&service=" + local_login_url)
if err != nil {
log.Fatalf("ERROR: %s\n", err)
return "Unable to validate the ticket"
}
bs, _ := ioutil.ReadAll(resp.Body)
split := strings.Split(string(bs), "\n")
ticketValid, login := split[0] == "yes", split[1]
if ticketValid {
s.Set("login", login)
ctx.Redirect("/")
return ""
}
return "Invalid login"
})
m.Run()
}
示例11: main
func main() {
m := macaron.Classic()
m.Use(macaron.Renderer())
m.Get("/", func(ctx *macaron.Context) {
ctx.HTML(200, "home")
})
m.Get("/ws", func(ctx *macaron.Context) {
conn, err := upgrader.Upgrade(ctx.Resp, ctx.Req.Request, nil)
if err != nil {
log.Printf("Fail to upgrade connection: %v", err)
return
}
stop := make(chan bool)
for {
_, data, err := conn.ReadMessage()
if err != nil {
if err != io.EOF {
log.Printf("Fail to read message: %v", err)
}
return
}
msg := string(data)
switch msg {
case "START":
if len(people) == 0 {
conn.WriteMessage(websocket.TextMessage, []byte("没人了我会乱说?"))
conn.Close()
return
}
go sendRandomInfo(conn, stop)
case "STOP":
stop <- true
default:
// Find corresponding name to display.
for i, p := range people {
if p.info == msg {
if err = conn.WriteMessage(websocket.TextMessage, []byte(p.name)); err != nil {
log.Printf("Fail to send message: %v", err)
return
}
people = append(people[:i], people[i+1:]...)
}
}
}
}
})
m.Run()
}
示例12: SetMiddlewares
func SetMiddlewares(m *macaron.Macaron) {
m.Use(macaron.Static("external", macaron.StaticOptions{
Expires: func() string { return "max-age=0" },
}))
m.Map(Log)
//modify default template setting
m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: "views",
Extensions: []string{".tmpl", ".html"},
Funcs: []template.FuncMap{},
Delims: macaron.Delims{"<<<", ">>>"},
Charset: "UTF-8",
IndentJSON: true,
IndentXML: true,
PrefixXML: []byte("macaron"),
HTMLContentType: "text/html",
}))
m.Use(macaron.Recovery())
}
示例13: newMacaronInstance
func newMacaronInstance() *macaron.Macaron {
m := macaron.Classic()
// Middlewares.
m.Use(macaron.Renderer(macaron.RenderOptions{
Funcs: []template.FuncMap{funcMap},
}))
m.Use(i18n.I18n(i18n.Options{
Langs: setting.Langs,
Names: setting.Names,
Redirect: true,
}))
// Routers.
m.Get("/", routers.MacaronDocs)
m.Get("/docs", routers.MacaronDocs)
m.Get("/docs/images/:all", routers.MacaronStatic)
m.Get("/docs/*", routers.MacaronDocs)
return m
}
示例14: newMacaron
func newMacaron() *macaron.Macaron {
macaron.Env = setting.Env
m := macaron.New()
m.Use(middleware.Logger())
m.Use(macaron.Recovery())
m.Use(toolbox.Toolboxer(m))
m.Use(func(ctx *macaron.Context) {
if ctx.Req.URL.Path == "/debug/vars" {
http.DefaultServeMux.ServeHTTP(ctx.Resp, ctx.Req.Request)
}
})
if setting.EnableGzip {
m.Use(middleware.Gziper())
}
mapStatic(m, "", "public")
mapStatic(m, "app", "app")
mapStatic(m, "css", "css")
mapStatic(m, "img", "img")
mapStatic(m, "fonts", "fonts")
mapStatic(m, "plugins", "plugins")
mapStatic(m, "robots.txt", "robots.txxt")
m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: path.Join(setting.StaticRootPath, "views"),
IndentJSON: macaron.Env != macaron.PROD,
Delims: macaron.Delims{Left: "[[", Right: "]]"},
}))
if setting.EnforceDomain {
m.Use(middleware.ValidateHostHeader(setting.Domain))
}
m.Use(middleware.GetContextHandler())
m.Use(middleware.Sessioner(&setting.SessionOptions))
return m
}
示例15: newMacaron
func newMacaron() *macaron.Macaron {
macaron.Env = setting.Env
m := macaron.New()
m.Use(middleware.Logger())
m.Use(macaron.Recovery())
if setting.EnableGzip {
m.Use(middleware.Gziper())
}
for _, route := range plugins.StaticRoutes {
pluginRoute := path.Join("/public/plugins/", route.Url)
log.Info("Plugin: Adding static route %s -> %s", pluginRoute, route.Path)
mapStatic(m, route.Path, "", pluginRoute)
}
mapStatic(m, setting.StaticRootPath, "", "public")
mapStatic(m, setting.StaticRootPath, "app", "app")
mapStatic(m, setting.StaticRootPath, "css", "css")
mapStatic(m, setting.StaticRootPath, "img", "img")
mapStatic(m, setting.StaticRootPath, "fonts", "fonts")
mapStatic(m, setting.StaticRootPath, "robots.txt", "robots.txt")
m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: path.Join(setting.StaticRootPath, "views"),
IndentJSON: macaron.Env != macaron.PROD,
Delims: macaron.Delims{Left: "[[", Right: "]]"},
}))
if setting.EnforceDomain {
m.Use(middleware.ValidateHostHeader(setting.Domain))
}
m.Use(middleware.GetContextHandler())
m.Use(middleware.Sessioner(&setting.SessionOptions))
return m
}