本文整理匯總了Golang中github.com/codegangsta/martini-contrib/render.Renderer函數的典型用法代碼示例。如果您正苦於以下問題:Golang Renderer函數的具體用法?Golang Renderer怎麽用?Golang Renderer使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Renderer函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
githubAccessToken := os.Getenv("GITHUB_ACCESS_TOKEN")
if githubAccessToken == "" {
fmt.Println("Create new tokens via https://github.com/settings/applications 'Personal Access Tokens' section")
log.Fatalln("Please set environment variable $GITHUB_ACCESS_TOKEN")
}
t := &oauth.Transport{
Token: &oauth.Token{AccessToken: githubAccessToken},
}
client = github.NewClient(t.Client())
m := martini.Classic()
m.Use(render.Renderer())
m.Get("/github/:org/:repo/pull/(?P<pull_id>\\d+).(?P<badge_type>(svg|png|json))", prBadgeHandler)
m.Get("/github/:org/:repo/pull/:pull_id", prRedirectHandler)
m.Get("/github/:org/:repo/issues/(?P<issue_id>\\d+).(?P<badge_type>(svg|png|json))", issueBadgeHandler)
m.Get("/github/:org/:repo/issues/:issue_id", issueRedirectHandler)
// Redirect to blog post for any other route (e.g. root route) until some human website implemented
m.NotFound(func(render render.Render) {
render.Redirect("https://blog.starkandwayne.com/2014/12/30/live-github-pr-status-in-your-blogs-docs/")
})
m.Run()
}
示例2: main
func main() {
siteMap = NewDefaultSiteMap()
m := martini.Classic()
m.Use(render.Renderer(render.Options{
Layout: "master",
}))
m.Get("/favicon.ico", func() {})
m.Get("/:lang/contact", contactHandler)
m.Get("/:lang/search", searchHandler)
// handler for atom and rss feeds.
m.Get("/:lang/feed/:feed/**.xml", feedHandler)
m.Get("/", markdownHandler)
m.Get("/:lang", markdownHandler)
m.Get("/:lang/**", markdownHandler)
m.Post("", siteWebhookHandler)
go RebuildSearchIndex(siteMap.GetPages())
// RunEditor(siteMap, "3001")
m.Run()
}
示例3: InitServer
func InitServer() *martini.ClassicMartini {
envFileName := martini.Env + ".env"
err := godotenv.Load(envFileName)
if err != nil {
log.Fatalf("Error loading: %s", envFileName)
}
m := martini.Classic()
m.Map(db.Connect())
m.Use(render.Renderer(render.Options{
Layout: "layout",
}))
m.Get("/", func(r render.Render) {
r.HTML(200, "home", "")
})
m.Get("/api/projects", controllers.ProjectIndex)
m.Get("/api/projects/new", controllers.ProjectNew)
m.Get("/api/projects/:id", controllers.ProjectGet)
m.Post("/api/projects", binding.Bind(models.Project{}), controllers.ProjectCreate)
m.Put("/api/projects/:id", binding.Bind(models.Project{}), controllers.ProjectUpdate)
m.Delete("/api/projects/:id", controllers.ProjectDelete)
return m
}
示例4: main
func main() {
fmt.Println("fmt included for debug. remove for production.")
m := martini.Classic()
m.Use(render.Renderer(render.Options{
Directory: "template",
Layout: "layout",
Extensions: []string{".html"},
}))
m.Get("/", func(r render.Render) {
random_string := RandomString(10, 30)
r.HTML(200, "main", "/d/"+random_string)
})
/* Main route handles incoming ** from user */
m.Get("/d/**", func(params martini.Params, r render.Render) {
/* Execute ruby script to parse the command */
cmd := exec.Command("ruby", "./interpreter/parser.rb", string(params["_1"]))
translation, _ := cmd.Output()
data := struct {
URL_string string
JS_string string
}{
params["_1"],
string(translation),
}
r.HTML(200, "d", data)
})
m.Run()
}
示例5: main
func main() {
m := martini.Classic()
// render middleware
// https://github.com/codegangsta/martini-contrib/tree/master/render
m.Use(render.Renderer(render.Options{
Directory: ".",
}))
// This will set the Content-Type header to "text/html; charset=UTF-8"
m.Get("/wishes", func(r render.Render) {
r.HTML(200, "martini-02", nil)
})
// This will set the Content-Type header to "text/html; charset=UTF-8"
m.Get("/text", func(r render.Render) {
r.HTML(200, "hello", "world")
})
// This will set the Content-Type header to "application/json; charset=UTF-8"
m.Get("/json", func(r render.Render) {
r.JSON(200, map[string]interface{}{"hello": "world"})
})
m.Run()
}
示例6: init
func init() {
cfg := new(config)
in, err := ioutil.ReadFile("config.yaml")
if err != nil {
log.Fatal(err)
}
err = goyaml.Unmarshal(in, cfg)
if err != nil {
log.Fatal(err)
}
flag.Parse()
log.SetOutputLevel(log.Ldebug)
if *environment == "development" {
opts = &cfg.Development
} else {
opts = &cfg.Production
}
fmt.Println("== environment:", *environment, "==")
utils.Dump(opts)
conf.ACCESS_KEY = opts.AccessKey
conf.SECRET_KEY = opts.SecretKey
// render html templates from templates directory
m.Use(render.Renderer(render.Options{
Layout: "layout",
}))
InitRouter()
}
示例7: Route
func Route(m *martini.ClassicMartini) {
m.Use(render.Renderer())
m.Get("/", func(r render.Render) {
r.HTML(200, "index", nil)
})
//post handlers
Signup(m)
Signin(m)
m.Get("/inspect", func() string {
return "Hello inspect!"
})
m.Get("/add", func() string {
return "Hello add!"
})
m.Post("/inspect", func() string {
return "Hello inspect!"
})
m.Post("/add", func() string {
return "Hello add!"
})
}
示例8: main
func main() {
var port int
flag.IntVar(&port, "port", 3001, "server port")
flag.Parse()
fmt.Println("Port: ", port)
endpoint := "unix:///var/run/docker.sock"
var err error
client, err = docker.NewClient(endpoint)
if err != nil {
panic(err)
}
m := martini.Classic()
m.Use(render.Renderer())
m.Get("/", func(r render.Render) {
r.JSON(http.StatusOK, getSystemMonitorSample())
})
m.Get("/:name", func(args martini.Params, r render.Render) {
name := args["name"]
sample, err := getContainerMonitorSample(name)
if err == nil {
r.JSON(http.StatusOK, sample)
} else {
r.JSON(http.StatusBadRequest, err)
}
})
http.Handle("/", m)
http.ListenAndServe(":"+strconv.Itoa(port), nil)
}
示例9: main
func main() {
m := martini.Classic()
// specify the layout to use when rendering HTML
m.Use(render.Renderer(render.Options{
Layout: "layout",
}))
// use the Mongo middleware
m.Use(DB())
// list of all cribs
m.Get("/", func(r render.Render, db *mgo.Database) {
r.HTML(200, "list", All(db))
})
/*
create a new crib the form submission. Contains some martini magic. The call
to binding.Form(Crib{}) parses out form data when the request comes in.
It binds the data to the struct, maps it to the request context and
injects into our next handler function to insert into Mongodb.
*/
m.Post("/", binding.Form(Crib{}), func(crib Crib, r render.Render, db *mgo.Database) {
db.C("cribs").Insert(crib)
r.HTML(200, "list", All(db))
})
// display the crib for a specific user
m.Get("/:handle", func(params martini.Params, r render.Render, db *mgo.Database) {
r.HTML(200, "display", Fetch(db, params["handle"]))
})
http.ListenAndServe(":8080", m)
}
示例10: main
func main() {
m := martini.Classic()
dbMap := initDb()
m.Map(dbMap)
store := sessions.NewCookieStore([]byte("nonotestetstsst"))
m.Use(sessions.Sessions("gogonki", store))
m.Use(render.Renderer())
m.Get("/", Index)
m.Get("/coords", Coords)
m.Get("/move/:x/:y", Move) // ToDo: make this post request
m.Get("/state", GetState)
m.Get("/profile", ShowProfile)
m.Get("/login", LoginForm)
m.Post("/login", Login)
m.Get("/logout", Logout)
m.Post("/create", binding.Bind(User{}), CreateUser)
m.Get("/signup", SignupForm)
m.Post("/signup", Signup)
m.Post("/create-room", CreateRoom)
m.Post("/list-rooms", ListRooms)
//m.Use(Auth)
m.Run()
}
示例11: main
func main() {
fs, err := filestore.New("s3")
if err != nil {
log.Fatal(err)
}
port := os.Getenv("PORT")
m := martini.Classic()
m.Map(fs)
m.Use(martini.Static("../web/public"))
m.Use(render.Renderer(render.Options{
Directory: "../web/templates",
Layout: "layout",
}))
m.Get("/", func(fs *filestore.S3, r render.Render) {
files, err := fs.List("builds")
sort.Sort(ByTime(files))
if err != nil {
log.Fatal(err)
}
r.HTML(200, "home", files)
})
log.Printf("starting server at %s", port)
err = http.ListenAndServe(":"+port, m)
if err != nil {
log.Fatal(err)
}
}
示例12: main
func main() {
m := martini.Classic()
m.Use(render.Renderer(render.Options{
Directory: "templates",
Layout: "layout",
Extensions: []string{".html"},
Delims: render.Delims{"{[{", "}]}"},
Funcs: []template.FuncMap{
{
"formatTime": func(args ...interface{}) string {
t1 := time.Unix(args[0].(int64), 0)
return t1.Format(time.Stamp)
},
"unescaped": func(args ...interface{}) template.HTML {
return template.HTML(args[0].(string))
},
},
},
}))
newmap := map[string]interface{}{}
m.Use(martini.Static("assets"))
m.Get("/", func(args martini.Params, r render.Render) string {
r.HTML(200, "index", newmap)
return ""
})
m.Run()
}
示例13: main
func main() {
m := martini.Classic()
m.Use(render.Renderer(render.Options{
Directory: "templates",
Layout: "layout",
Funcs: []template.FuncMap{
{
"formatTime": func(args ...interface{}) string {
t1 := time.Unix(args[0].(int64), 0)
return t1.Format(time.Stamp)
},
"unescaped": func(args ...interface{}) template.HTML {
return template.HTML(args[0].(string))
},
},
},
}))
m.Get("/", func(r render.Render) {
d := map[string]interface{}{"title": "Main", "message": "SUCCESS!"}
r.HTML(200, "main", d)
})
m.Run()
}
示例14: main
func main() {
m := martini.Classic()
m.Use(render.Renderer())
m.Get("/", func(r render.Render) {
data := map[string]interface{}{}
data["name"] = "Example Website"
data["content"] = "Welcome home."
data["title"] = "Home"
r.HTML(200, "main", data)
})
m.Get("/about", func(r render.Render) {
data := map[string]interface{}{}
data["name"] = "Example Website"
data["content"] = "About us."
data["title"] = "About"
r.HTML(200, "main", data)
})
m.Get("/contact", func(r render.Render) {
data := map[string]interface{}{}
data["name"] = "Example Website"
data["content"] = "Contact us."
data["title"] = "Contact"
r.HTML(200, "main", data)
})
m.Run()
}
示例15: main
func main() {
//go ServeWebsocket()
m := martini.Classic()
m.Use(render.Renderer(render.Options{
Layout: "layout",
}))
m.Use(martini.Static("assets"))
m.Get("/", func(r render.Render) {
r.HTML(200, "index", "index")
})
// api group
m.Group("/api", func(r martini.Router) {
r.Post("/log", binding.Bind(Log{}), NewLog)
r.Get("/log/:appname", func(args martini.Params, r render.Render) {
logs, err := GetLogForApp(args["appname"])
if err != nil {
r.JSON(200, map[string]interface{}{})
}
r.JSON(200, logs)
})
})
//websocket
m.Get("/sock/:appname", socketHandler)
m.Run()
}