Pkg.go.dev is a new destination for Go discovery & docs. Check it out at pkg.go.dev/github.com/alash3al/olive-go and share your feedback.

package olive

import "github.com/alash3al/olive-go"

Olive Version 3.0

olive.go

❖ func Handler(h http.Handler, rtrn bool) handler

Convert any http.Handler compatible handler to an internal handler, and rtrn is what will be returned for "[don't]run the next matched route with the same method and patttern"

❖ type App struct { // contains filtered or unexported fields }

Our main structure

Create a new instance

❖ func (self *App) ANY(path string, cb handler) *App

Handle ANY request method for the specified path with the specified callback; NOTE: this is based on "func(self *App) METHOD()"

❖ func (self *App) CONNECT(path string, cb handler) *App

Handle CONNECT request for the specified path with the specified callback; NOTE: this is based on "func(self *App) METHOD()"

❖ func (self *App) DELETE(path string, cb handler) *App

Handle DELETE request for the specified path with the specified callback; NOTE: this is based on "func(self *App) METHOD()"

❖ func (self *App) GET(path string, cb handler) *App

Handle GET request for the specified path with the specified callback; NOTE: this is based on "func(self *App) METHOD()"

❖ func (self *App) GroupBy(by, pattern string, fn grouper) *App

Group multiple routes by the specified section and its pattern with its grouper, olive currently supports by "host" or "path" only .

❖ func (self *App) HEAD(path string, cb handler) *App

Handle HEAD request for the specified path with the specified callback; NOTE: this is based on "func(self *App) METHOD()"

An Alias to http.ListenAndServe

❖ func (self App) ListenTLS(addr string, certFile string, keyFile string) error

An Alias to http.ListenAndServeTLS

❖ func (self *App) METHOD(method, path string, cb handler) *App

Handle the specified custom method for the specified path; NOTE: method could be a "regexp string"; NOTE: path could be a "regexp string";

❖ func (self *App) OPTIONS(path string, cb handler) *App

Handle OPTIONS request for the specified path with the specified callback; NOTE: this is based on "func(self *App) METHOD()"

❖ func (self *App) PATCH(path string, cb handler) *App

Handle PATCH request for the specified path with the specified callback; NOTE: this is based on "func(self *App) METHOD()"

❖ func (self *App) POST(path string, cb handler) *App

Handle POST request for the specified path with the specified callback; NOTE: this is based on "func(self *App) METHOD()"

❖ func (self *App) PUT(path string, cb handler) *App

Handle PUT request for the specified path with the specified callback; NOTE: this is based on "func(self *App) METHOD()"

❖ func (self App) ServeHTTP(res http.ResponseWriter, req *http.Request)

Dispatch all registered routes

❖ func (self *App) TRACE(path string, cb handler) *App

Handle TRACE request for the specified path with the specified callback; NOTE: this is based on "func(self *App) METHOD()"

❖ type Context struct { Req *http.Request Res http.ResponseWriter Params []string Vars map[string]interface{} }

A request context and properties

❖ func (self Context) AddHeader(k, v string)

Add a header field

Delete the specified header field

Read the request body into the provided variable, it will read the body as json if the specified "v" isn't ([]byte, io.Writer) .

Get the specified header field "from the request"

Return the url query vars, if body is true, then this function will parse the request body as x-www-form-urlencoded .

Limit the size of the request body .

Write to the client, this function will detect the type of the data, it will send the data as json if the specified input isn't (string, []byte, *template.Template and io.Reader), it execute the input as html template if the first argument is *template.Template and second argument is template's data, you MUST LimitBody() to prevent memory-leaks attacks .

❖ func (self Context) SetHeader(k, v string)

Set a http header field

Set the status code

Package olive imports 8 packages (graph). Updated 2016-07-15. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).