package main
import "gopkg.in/macaron.v1"
func main() {
m := macaron.Classic()
m.Get("/", func() string {
return "Hello world!"
})
m.Run()
}
m.Group("/books", func() {
m.Get("/:id", GetBooks)
m.Post("/new", NewBook)
m.Put("/update/:id", UpdateBook)
m.Delete("/delete/:id", DeleteBook)
m.Group("/chapters", func() {
m.Get("/:id", GetBooks)
m.Post("/new", NewBook)
m.Put("/update/:id", UpdateBook)
m.Delete("/delete/:id", DeleteBook)
}, MyMiddleware3, MyMiddleware4)
}, MyMiddleware1, MyMiddleware2)
package main
import "gopkg.in/macaron.v1"
func main() {
m := macaron.Classic()
m.Use(macaron.Renderer())
m.Get("/", func(ctx *macaron.Context) {
ctx.Data["Name"] = "jeremy"
ctx.HTML(200, "hello") // 200 is the response code.
})
m.Run()
}
import (
"gopkg.in/macaron.v1"
"github.com/go-macaron/i18n"
)
func main() {
m := macaron.Classic()
m.Use(i18n.I18n(i18n.Options{
Langs: []string{"en-US", "zh-CN"},
Names: []string{"English", "简体中文"},
}))
m.Get("/", func(locale i18n.Locale) string {
return "current language is" + locale.Lang
})
// Use in handler.
m.Get("/trans", func(ctx *macaron.Context) string {
return ctx.Tr("hello %s", "world")
})
m.Run()
}