Gear是Go语言下的一个轻量级、可组合、高性能的Web服务框架。由 Teambition 开发,用于开发 SOA服务层。其设计参考了Go生态下现有的近十款Web框架和Node.js生态的 koa、Toa 等框架。
Demo
package mainimport ( "fmt" "os" "github.com/teambition/gear" "github.com/teambition/gear/logging")func main() { app := gear.New() // Add logging middleware app.UseHandler(logging.Default()) // Add router middleware router := gear.NewRouter() router.Use(func(ctx *gear.Context) error { // do some thing. fmt.Println("Router middleware...", ctx.Path) return nil }) router.Get("/", func(ctx *gear.Context) error { return ctx.HTML(200, "<h1>Hello, Gear!</h1>") }) app.UseHandler(router) app.Error(app.Listen(":3000"))}
评论