| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
JoniSeidel
9年前发布

Olive - just a tiny very simple web app framework for Go

来自: https://github.com/alash3al/olive-go

olive.go

Just a lightweight golang web application middleware

Author

Mohammed Al Ashaal, a full-stack developer

Install

go get github.com/alash3al/olive-go

Docs

Godoc

Quick overview:

package main    import "net/http"  import "github.com/alash3al/olive-go"    func main() {      olive.New().GET("/", func(ctx *olive.Context) bool {          ctx.SetBody("index")          // return false = "don't run the next matched route with the same method and pattern if any"          // this feature allows you to run multiple routes with the same properties          return false      }).ANY("/page/?(.*?)", func(ctx *olive.Context) bool {          var body []byte          ctx.LimitBody(20)          err := ctx.GetBody(&body)          ctx.SetBody("this is your input \n")          ctx.SetBody(body)          _ = err          return true      }).GET("/page", func(ctx *olive.Context) bool {          ctx.SetBody([]byte("hi !"))          return false      }).POST("/page/([^/]+)/and/([^/]+)", func(ctx *olive.Context) bool {          var input map[string]string          ctx.GetBody(&input, 512) // parse the request body into {input} and returns error if any          ctx.SetBody(ctx.Params)          return false      }).GroupBy("path", "/api/v1", func(ApiV1 *olive.App){          ApiV1.GET("/ok", func(ctx *olive.Context) bool {              ctx.Res.Write([]byte("api/v1/ok"))              return false          }).GET("/page/([^/]+)/and/([^/]+)", func(ctx *olive.Context) bool {              ctx.Res.Write([]byte("api/v1/ " + ctx.Params[0] + " " + ctx.Params[1]))              return false          })      }).ANY("?.*?", olive.Handler(http.NotFoundHandler(), false)).Listen(":80")  }

Changes

Version 3.0

  • Context.GetQuery now accepts new param called body and its type is bool, so you can get the request body as url-decoded as url.Values
  • Context.GetBody now accepts one paramater, and you don't need to make([]byte, ...) just pass a &v where v is []byte
  • added Context.LimitBody to limit the request body to prevent any memory-leaks attacks while reading it using Context.GetBody .

Version 2.0

  • removed panics handler
  • removed Context.AddHeaders() and Context.SetHeaders()
  • added Context.DelHeader()
  • renamed Context.Query() to Context.GetQuery()
  • renamed Context.Body() to Context.GetBody()
  • renamed Context.Send() to Context.SetBody()
  • added support for html templates in Context.SetBody()
  • renamed App.Group() to App.GroupBy
  • add support for custom vhost routing

 本文由用户 JoniSeidel 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1455151045589.html
HTML 中间件 Go语言 Web框架