Documentation
¶
Overview ¶
A tiny http framework perfect for building web services . *
package main
import "net/http"
import "github.com/alash3al/olive-go"
func main() {
olive.New().GET("/", func(ctx *olive.Context) bool {
ctx.Res.Write([]byte("index"))
return false
}).CONNECT("/", func(ctx *olive.Context) bool {
// olive automatically catch any panic and recover it to the
// "stdout" using "log" package .
panic("connect method !")
return false
}).ANY("/page/?(.*?)", func(ctx *olive.Context) bool {
ctx.Res.Write([]byte("i'm the parent \n"))
return true
}).GET("/page", func(ctx *olive.Context) bool {
ctx.Res.Write([]byte("page"))
return false
}).GET("/page/([^/]+)/and/([^/]+)", func(ctx *olive.Context) bool {
ctx.Res.Write([]byte(ctx.Params[0] + " " + ctx.Params[1]))
return false
}).Group("/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")
}
Index ¶
- func Handler(h http.Handler, rtrn bool) callback
- type App
- func (self *App) ANY(path string, cb callback) *App
- func (self *App) CONNECT(path string, cb callback) *App
- func (self *App) DELETE(path string, cb callback) *App
- func (self *App) GET(path string, cb callback) *App
- func (self *App) Group(path string, fn gfn) *App
- func (self *App) HEAD(path string, cb callback) *App
- func (self App) Listen(addr string) error
- func (self App) ListenTLS(addr string, certFile string, keyFile string) error
- func (self *App) METHOD(method, path string, cb callback) *App
- func (self *App) OPTIONS(path string, cb callback) *App
- func (self *App) PATCH(path string, cb callback) *App
- func (self *App) POST(path string, cb callback) *App
- func (self *App) PUT(path string, cb callback) *App
- func (self App) ServeHTTP(res http.ResponseWriter, req *http.Request)
- func (self *App) TRACE(path string, cb callback) *App
- type Context
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
Our main structure
func (*App) ANY ¶
Handle ANY request method for the specified path with the specified callback; NOTE: this is based on "func(self *App) METHOD()"
func (*App) CONNECT ¶
Handle CONNECT request for the specified path with the specified callback; NOTE: this is based on "func(self *App) METHOD()"
func (*App) DELETE ¶
Handle DELETE request for the specified path with the specified callback; NOTE: this is based on "func(self *App) METHOD()"
func (*App) GET ¶
Handle GET request for the specified path with the specified callback; NOTE: this is based on "func(self *App) METHOD()"
func (*App) Group ¶
Group some of routes under the specified path/pattern the group function will pass the current instance of App to the grouper .
func (*App) HEAD ¶
Handle HEAD request for the specified path with the specified callback; NOTE: this is based on "func(self *App) METHOD()"
func (*App) METHOD ¶
Handle the specified custom method for the specified path NOTE: method could be a "regexp string" NOTE: path could be a "regexp string"
func (*App) OPTIONS ¶
Handle OPTIONS request for the specified path with the specified callback; NOTE: this is based on "func(self *App) METHOD()"
func (*App) PATCH ¶
Handle PATCH request for the specified path with the specified callback; NOTE: this is based on "func(self *App) METHOD()"
func (*App) POST ¶
Handle POST request for the specified path with the specified callback; NOTE: this is based on "func(self *App) METHOD()"
func (*App) PUT ¶
Handle PUT request for the specified path with the specified callback; NOTE: this is based on "func(self *App) METHOD()"