本文整理汇总了Golang中github.com/martini-contrib/render.Renderer函数的典型用法代码示例。如果您正苦于以下问题:Golang Renderer函数的具体用法?Golang Renderer怎么用?Golang Renderer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Renderer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: http
func http() {
server := martini.Classic()
server.Use(martini.Static("public", martini.StaticOptions{
Prefix: "public",
}))
server.Use(martini.Static("bower_components", martini.StaticOptions{
Prefix: "bower_components",
}))
server.Use(render.Renderer(render.Options{
Extensions: []string{".tmpl", ".html"},
Delims: render.Delims{"{[{", "}]}"},
}))
server.Get("/", func(r render.Render) {
r.HTML(200, "index", nil)
})
//
server.Get("/clients/:pid", func(params martini.Params, r render.Render) {
r.HTML(200, "index", params["pid"])
})
type jd map[string]interface{}
type ja []interface{}
// json api
server.Get("/api/clients", func(r render.Render) {
client_info := ja{}
for _, c := range compositors {
var surfaces []Surface
for _, s := range c.Surfaces {
surfaces = append(surfaces, *s)
}
client_info = append(client_info, jd{
"pid": c.Pid,
"ss": surfaces,
})
}
r.JSON(200, client_info)
})
// websocket api
server.Get("/api/clients", websocket.Handler(func(ws *websocket.Conn) {
}).ServeHTTP)
server.Get("/api/clients/:pid", websocket.Handler(func(ws *websocket.Conn) {
}).ServeHTTP)
server.Run()
}
示例2: apiv1
func apiv1() {
url := "/api/v1"
m.Group(url+"/workplace", func(router martini.Router) {
router.Post("/auth", binding.Json(controllers.InputWorkplaceAuth{}), controllers.WorkplaceAuth)
//router.Post("/test", binding.Json(controllers.Test{}), controllers.WorkplacePing)
//router.Post("/add", binding.Json(controllers.Add{}), controllers.WorkplaceAdd)
//update
//delete
//import
}, render.Renderer())
m.Group(url+"/promocode", func(router martini.Router) {
router.Post("/calc", binding.Json(controllers.InputPromocodeCalc{}), controllers.PromocodeCalc)
//update
//delete
//import
}, render.Renderer())
m.Group(url+"/document", func(router martini.Router) {
router.Post("/add", binding.Json(controllers.InputDocumentAdd{}), controllers.DocumentAdd)
//update
//delete
//import
}, render.Renderer())
}
示例3: Start
// Entry point for running the application.
// It defines all routes and middleware used
// and starts the underlying server.
func Start() {
// Set up our Martini instance
m := martini.Classic()
// Middleware
// m.Use(gzip.All())
m.Use(render.Renderer())
// Routes
m.Group("/admin", func(r martini.Router) {
a := handlers.Admin{}
r.Get("", a.Index)
r.Get("/posts", a.Posts.Index)
r.Get("/posts/new", a.Posts.New)
r.Get("/posts/:id/edit", a.Posts.Edit)
}, render.Renderer(render.Options{
Layout: "admin/layout",
}))
m.Group("/api", func(r martini.Router) {
a := handlers.Api{}
r.Get("", a.Index)
r.Get("/posts", a.Posts.Index)
r.Post("/posts", a.Posts.Create)
r.Get("/posts/:id", a.Posts.Show)
r.Get("/render/markdown", a.Render.Markdown)
})
// Serve from static if possible
m.Use(martini.Static(util.Config().App.SiteDir))
m.Run()
}
示例4: Run
func (this *Server) Run(withRandomPort ...bool) {
this.Martini.Use(cors.Allow(&cors.Options{
AllowAllOrigins: true,
AllowMethods: []string{"PUT", "PATCH", "DELETE", "GET", "OPTIONS", "POST"},
AllowCredentials: true,
}))
this.Martini.Use(render.Renderer())
this.Martini.Group("/eureka", func(r martini.Router) {
for _, request := range this.getRequestsEureka() {
request.SetRoutes(r)
}
})
this.registerJobsRoutes()
if len(withRandomPort) > 0 && withRandomPort[0] {
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
loggerServer.Severe("Error when getting a free random port: %v", err.Error())
}
host := listener.Addr().String()
listener.Close()
this.Martini.RunOnAddr(host)
} else if config.GetConfig().Host != "" {
this.Martini.RunOnAddr(config.GetConfig().Host)
} else {
this.Martini.Run()
}
}
示例5: Start
func Start(port string, onStart func()) {
// Logging init
flag.Set("log_dir", utils.GetRuntimeDir(config.GetString("log_dir")))
flag.Set("alsologtostderr", "true")
flag.Parse()
defer glog.Flush()
m := martini.Classic()
m.Use(render.Renderer(render.Options{
Charset: "UTF-8", // Sets encoding for json and html content-types. Default is "UTF-8".
Delims: render.Delims{"${", "}"},
Directory: utils.GetRuntimeDir("resources/views"),
}))
m.Use(martini.Static(utils.GetRuntimeDir("public")))
controller.MappingController(m)
http.Handle("/rpc", rpc.GetServer())
http.Handle("/", m)
if db.IsConnected() {
defer db.Close()
}
onStart()
for _, fn := range methods {
go fn()
}
http.ListenAndServe(":"+port, nil)
}
示例6: main
func main() {
defer clean()
mck := shardmaster.MakeClerk(smh)
mck.Join(gids[0], ha[0])
ck.Subscribe("a")
ck.Subscribe("b")
ck.Subscribe("c")
ck.Subscribe("d")
ck.Subscribe("e")
defer cleanupClerk(ck)
go listener(ck)
go h.run()
m := martini.Classic()
m.Use(render.Renderer())
m.Get("/", func(r render.Render) {
r.HTML(200, "index", "")
})
m.Get("/ws", wsHandler)
m.Run()
}
示例7: main
func main() {
log.Println("server start11")
fmt.Printf("access_token:%s", ACCESS_TOKEN)
m := martini.Classic()
m.Handlers(martini.Recovery())
m.Use(render.Renderer(render.Options{
Extensions: []string{".html", ".shtml"},
}))
m.Get("/", checkSignatureHandler)
m.Post("/", transceiverMsgHandler)
m.Get("/createMenu", createMenuHandler)
m.Get("/hi", func() string {
return "Hello world!"
})
http.Handle("/", m)
if martini.Env == martini.Dev {
HOST = ":8080"
} else {
HOST = ":80"
}
log.Printf("start web server on %s", HOST)
http.ListenAndServe(HOST, nil)
}
示例8: Routes
func Routes() http.Handler {
// Middlewares are setup and run before each incoming request
// the ones named like *Provider provide singleton instances
// of injectable objects. For instance appx, logger, appengine context
// can be injected in our routes handlers (a.k.a controllers)
router := martini.Classic()
router.Use(render.Renderer())
router.Use(middlewares.AppengineContextProvider)
router.Use(middlewares.LoggerProvider)
router.Use(middlewares.AppxProvider)
router.Post("/login", binding.Bind(controllers.LoginForm{}), controllers.Login)
router.Group("/account", func(r martini.Router) {
r.Post("/registerDropbox", binding.Bind(controllers.RegisterDropboxForm{}), controllers.RegisterDropbox)
r.Post("/update", binding.Bind(controllers.AccountUpdateForm{}), controllers.UpdateAccount)
r.Group("/dropbox", func(r martini.Router) {
r.Post("/init", controllers.DropboxInit)
r.Post("/delta", controllers.DropboxDelta)
}, middlewares.ExternalServiceAuthorizationProvider)
r.Group("/trails", func(r martini.Router) {
r.Get("/next_evaluation", controllers.TrailNextEvaluation)
r.Patch("/:trail_id/like", controllers.TrailLike)
r.Patch("/:trail_id/dislike", controllers.TrailDislike)
r.Get("/tags", controllers.Tags)
r.Get("/tags/:tag_id", controllers.TagTrails)
})
}, middlewares.AuthorizationAccountProvider)
return router
}
示例9: main
func main() {
m := martini.Classic()
m.Map(SetupDB())
m.Use(martini.Logger())
m.Use(render.Renderer(render.Options{
Layout: "layout",
}))
store := sessions.NewCookieStore([]byte(CookieSecret))
m.Use(sessions.Sessions("bunkaisession", store))
log.Println("env is", martini.Env)
m.Map(martini.Env)
m.Group("/", func(m martini.Router) {
m.Get("", Home)
}, AssetMap)
m.Group("/api", func(m martini.Router) {
m.Post("/login", PostLogin)
m.Post("/users", UserCreate)
m.Group("/sentences", func(m martini.Router) {
m.Post("", SentenceCreate)
m.Get("", SentenceList)
m.Delete("/:id", SentenceDelete)
}, RequireLogin)
m.Group("/users", func(m martini.Router) {
m.Post("/logout", Logout)
m.Get("/me", UserGet)
}, RequireLogin)
})
m.Run()
}
示例10: App
func App() *martini.ClassicMartini {
m := martini.Classic()
m.Use(gzip.All())
m.Use(render.Renderer(render.Options{
Directory: "templates",
}))
m.Use(cors.Allow(&cors.Options{
AllowAllOrigins: true,
}))
m.Get("", Index)
m.Group("/repos", func(r martini.Router) {
r.Get("", ReposIndex)
r.Get("/:name", ReposShow)
})
m.Group("/orgs", func(r martini.Router) {
r.Get("", OrgsIndex)
r.Get("/:id", OrgsShow)
})
m.Group("/users", func(r martini.Router) {
r.Get("", UserIndex)
r.Get("/:id", UserShow)
})
m.Get("/stats", StatsIndex)
m.Get("/issues", IssuesIndex)
return m
}
示例11: main
func main() {
log.Info("启动")
//读取配置文件
base.BaseConfig.Read("config.json")
// 初始化数据库
base.InitDb()
// 检查文件完整性
//err := base.CheckFiles()
//if(err!=nil){
// log.Error(err)
// return
//}
m := martini.Classic()
// gzip支持
m.Use(gzip.All())
// 模板支持
m.Use(render.Renderer())
//
m.Get("/meta.js", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/javascript")
w.Write([]byte(base.GetMetaJs()))
})
// websocket 支持
m.Get("/ws", websocket.Handler(base.WsHandler).ServeHTTP)
m.NotFound(func(r render.Render) {
r.HTML(404, "404", nil)
})
log.Info(fmt.Sprintf("访问地址 http://localhost:%d", base.BaseConfig.Web.Port))
// 端口号
http.ListenAndServe(fmt.Sprintf(":%d", base.BaseConfig.Web.Port), m)
// m.Run()
log.Info("退出")
}
示例12: main
func main() {
m := martini.Classic()
store := sessions.NewCookieStore([]byte("secret-isucon"))
m.Use(sessions.Sessions("isucon_go_session", store))
m.Use(martini.Static("../public"))
m.Use(render.Renderer(render.Options{
Layout: "layout",
}))
m.Get("/", func(r render.Render, session sessions.Session) {
r.HTML(200, "index", map[string]string{"Flash": getFlash(session, "notice")})
})
m.Post("/login", func(req *http.Request, r render.Render, session sessions.Session) {
user, err := attemptLogin(req)
notice := ""
if err != nil || user == nil {
switch err {
case ErrBannedIP:
notice = "You're banned."
case ErrLockedUser:
notice = "This account is locked."
default:
notice = "Wrong username or password"
}
session.Set("notice", notice)
r.Redirect("/")
return
}
session.Set("user_id", strconv.Itoa(user.ID))
r.Redirect("/mypage")
})
m.Get("/mypage", func(r render.Render, session sessions.Session) {
currentUser := getCurrentUser(session.Get("user_id"))
if currentUser == nil {
session.Set("notice", "You must be logged in")
r.Redirect("/")
return
}
currentUser.getLastLogin()
r.HTML(200, "mypage", currentUser)
})
m.Get("/report", func(r render.Render) {
r.JSON(200, map[string][]string{
"banned_ips": bannedIPs(),
"locked_users": lockedUsers(),
})
})
http.ListenAndServe(":8080", m)
}
示例13: main
func main() {
m := martini.Classic()
m.Map(SetupDB())
m.Use(render.Renderer(render.Options{
Layout: "layout",
}))
m.Get("/", func(ren render.Render, r *http.Request, db *sql.DB) {
searchTerm := "%" + r.URL.Query().Get("search") + "%"
rows, err := db.Query(`SELECT title, author, description FROM books
WHERE title ILIKE $1
OR author ILIKE $1
OR description ILIKE $1`, searchTerm)
PanicIf(err)
defer rows.Close()
books := []Book{}
for rows.Next() {
book := Book{}
err := rows.Scan(&book.Title, &book.Author, &book.Description)
PanicIf(err)
books = append(books, book)
}
ren.HTML(200, "books", books)
})
m.Run()
}
示例14: main
func main() {
autoUpdate()
m := martini.Classic()
m.Use(martini.Static("static"))
m.Use(render.Renderer())
m.Get("/", func(r render.Render) {
r.HTML(200, "content", []interface{}{getPage(1)})
})
m.Get("/api/:id", func(params martini.Params, r render.Render) {
s := strings.Trim(params["id"], " .)(")
id := atoi(s)
r.JSON(200, getPage(id))
})
m.Get("/page/:id", func(params martini.Params, r render.Render) {
s := strings.Trim(params["id"], " .)(")
id := atoi(s)
r.HTML(200, "content", []interface{}{getPage(id)})
})
http.ListenAndServe("0.0.0.0:8000", m)
m.Run()
}
示例15: main
func main() {
m := martini.Classic()
//middleware
m.Use(render.Renderer(render.Options{
Layout: "layout",
}))
m.Get("/", func(r render.Render) {
r.HTML(200, "index", "")
})
m.Get("/new", func(r render.Render) {
var v map[string]interface{}
values := url.Values{}
res, err := http.PostForm("http://requestb.in/api/v1/bins", values)
if err != nil {
r.JSON(500, map[string]interface{}{"error": err})
} else {
defer res.Body.Close()
err = json.NewDecoder(res.Body).Decode(&v)
if err != nil {
r.JSON(500, map[string]interface{}{"error": err})
}
}
r.HTML(200, "new", v)
})
m.Run()
}