neko: github.com/rocwong/neko Index | Files | Directories

package neko

import "github.com/rocwong/neko"

Index

Package Files

context.go helper.go logger.go neko.go recovery.go response_writer.go routergroup.go routerparams.go sessions.go utils.go

Constants

const (
    DEV  string = "development"
    PROD string = "production"
    TEST string = "test"
)

Variables

var NekoEnv = DEV

NekoEnv is the environment that Neko is executing in. The NEKO_ENV is read on initialization to set this variable.

func Version Uses

func Version() string

type Context Uses

type Context struct {
    Writer  ResponseWriter
    Req     *http.Request
    Session Session
    Keys    map[string]interface{}
    Params  routerParams
    Engine  *Engine

    HtmlEngine
    // contains filtered or unexported fields
}

func (*Context) Abort Uses

func (c *Context) Abort()

Forces the system to do not continue calling the pending handlers in the chain.

func (*Context) ClientIP Uses

func (c *Context) ClientIP() string

ClientIP returns more real IP address.

func (*Context) Get Uses

func (c *Context) Get(key string) (interface{}, error)

Get returns the value for the given key or an error if the key does not exist.

func (*Context) GetBasicSecureCookie Uses

func (ctx *Context) GetBasicSecureCookie(Secret, name string) (string, bool)

GetBasicSecureCookie returns given cookie value from request header with secret string.

func (*Context) GetCookie Uses

func (c *Context) GetCookie(name string) string

GetCookie returns given cookie value from request header.

func (*Context) GetSecureCookie Uses

func (ctx *Context) GetSecureCookie(name string) (string, bool)

GetSecureCookie returns given cookie value from request header with default secret string.

func (*Context) Json Uses

func (c *Context) Json(data interface{}, status ...int)

Serializes the given struct as JSON into the response body in a fast and efficient way. It also sets the Content-Type as "application/json".

func (*Context) Jsonp Uses

func (c *Context) Jsonp(callback string, data interface{}, status ...int)

Serializes the given struct as JSONP into the response body in a fast and efficient way. It also sets the Content-Type as "application/javascript".

func (*Context) MustGet Uses

func (c *Context) MustGet(key string) interface{}

MustGet returns the value for the given key or panics if the value doesn't exist.

func (*Context) Next Uses

func (c *Context) Next()

Next should be used only in the middlewares. It executes the pending handlers in the chain inside the calling handler.

func (*Context) Redirect Uses

func (c *Context) Redirect(location string, status ...int)

Redirect returns a HTTP redirect to the specific location. default for 302

func (*Context) Set Uses

func (c *Context) Set(key string, item interface{})

Sets a new pair key/value just for the specified context.

func (*Context) SetBasicSecureCookie Uses

func (ctx *Context) SetBasicSecureCookie(Secret, name, value string, others ...interface{})

SetBasicSecureCookie sets given cookie value to response header with secret string.

func (*Context) SetCookie Uses

func (c *Context) SetCookie(name, value string, others ...interface{})

SetCookie sets given cookie value to response header. ctx.SetCookie(name, value [, MaxAge, Path, Domain, Secure, HttpOnly])

func (*Context) SetHeader Uses

func (c *Context) SetHeader(key, value string)

SetHeader sets a response header.

func (*Context) SetSecureCookie Uses

func (ctx *Context) SetSecureCookie(name, value string, others ...interface{})

SetSecureCookie sets given cookie value to response header with default secret string.

func (*Context) Text Uses

func (c *Context) Text(data string, status ...int)

Writes the given string into the response body and sets the Content-Type to "text/plain".

func (*Context) Xml Uses

func (c *Context) Xml(data interface{}, status ...int)

Serializes the given struct as XML into the response body in a fast and efficient way. It also sets the Content-Type as "application/xml".

type Engine Uses

type Engine struct {
    *RouterGroup
    AppName string
    // contains filtered or unexported fields
}

func Classic Uses

func Classic(appName ...string) *Engine

Classic creates a classic Neko with some basic default middleware - neko.Logger and neko.Recovery.

func New Uses

func New() *Engine

New returns a new blank Engine instance without any middleware attached.

func (*Engine) Run Uses

func (c *Engine) Run(addr string) error

Run run the http server.

func (*Engine) RunTLS Uses

func (c *Engine) RunTLS(addr string, cert string, key string) error

Run run the https server.

func (*Engine) ServeHTTP Uses

func (c *Engine) ServeHTTP(res http.ResponseWriter, req *http.Request)

ServeHTTP makes the router implement the http.Handler interface.

func (*Engine) SetCookieSecret Uses

func (m *Engine) SetCookieSecret(secret string)

SetCookieSecret sets global default secure cookie secret.

func (*Engine) Use Uses

func (c *Engine) Use(middlewares ...HandlerFunc)

type HandlerFunc Uses

type HandlerFunc func(*Context)

func Logger Uses

func Logger() HandlerFunc

func Recovery Uses

func Recovery() HandlerFunc

Recovery returns a middleware that recovers from any panics and writes a 500 if there was one.

type HtmlEngine Uses

type HtmlEngine interface {
    Render(view string, context interface{}, status ...int) error
}

HtmlEngine is an interface for parsing html templates and redering HTML.

type JSON Uses

type JSON map[string]interface{}

type ResponseWriter Uses

type ResponseWriter interface {
    http.ResponseWriter
    http.Flusher
    Status() int
    // Size returns the size of the response body.
    Size() int
    Written() bool
    WriteHeaderNow()
    // Before allows for a function to be called before the ResponseWriter has been written to. This is
    // useful for setting headers or any other operations that must happen before a response has been written.
    Before(func(ResponseWriter))
}

type RouterGroup Uses

type RouterGroup struct {
    Handlers []HandlerFunc
    // contains filtered or unexported fields
}

func (*RouterGroup) Any Uses

func (c *RouterGroup) Any(relativePath string, handlers ...HandlerFunc)

Any is a shortcut for all request methods

func (*RouterGroup) DELETE Uses

func (c *RouterGroup) DELETE(relativePath string, handlers ...HandlerFunc)

DELETE is a shortcut for router.Handle("DELETE", path, handle)

func (*RouterGroup) GET Uses

func (c *RouterGroup) GET(relativePath string, handlers ...HandlerFunc)

GET is a shortcut for router.Handle("GET", path, handle)

func (*RouterGroup) Group Uses

func (c *RouterGroup) Group(relativePath string, fn func(*RouterGroup), handlers ...HandlerFunc) *RouterGroup

Creates a new router group. You should add all the routes that have common middlwares or the same path prefix. For example, all the routes that use a common middlware for authorization could be grouped.

func (*RouterGroup) HEAD Uses

func (c *RouterGroup) HEAD(relativePath string, handlers ...HandlerFunc)

HEAD is a shortcut for router.Handle("HEAD", path, handle)

func (*RouterGroup) Handle Uses

func (c *RouterGroup) Handle(httpMethod, relativePath string, handlers []HandlerFunc)

Handle registers a new request handle and middlewares with the given path and method. The last handler should be the real handler, the other ones should be middlewares that can and should be shared among different routes.

For GET, POST, PUT, PATCH and DELETE requests the respective shortcut functions can be used.

This function is intended for bulk loading and to allow the usage of less frequently used, non-standardized or custom methods (e.g. for internal communication with a proxy).

func (*RouterGroup) OPTIONS Uses

func (c *RouterGroup) OPTIONS(relativePath string, handlers ...HandlerFunc)

OPTIONS is a shortcut for router.Handle("OPTIONS", path, handle)

func (*RouterGroup) PATCH Uses

func (c *RouterGroup) PATCH(relativePath string, handlers ...HandlerFunc)

PATCH is a shortcut for router.Handle("PATCH", path, handle)

func (*RouterGroup) POST Uses

func (c *RouterGroup) POST(relativePath string, handlers ...HandlerFunc)

POST is a shortcut for router.Handle("POST", path, handle)

func (*RouterGroup) PUT Uses

func (c *RouterGroup) PUT(relativePath string, handlers ...HandlerFunc)

PUT is a shortcut for router.Handle("PUT", path, handle)

func (*RouterGroup) Static Uses

func (c *RouterGroup) Static(path, dir string)

Static serves files from the given file system root. Internally a http.FileServer is used, therefore http.NotFound is used instead of the Router's NotFound handler. To use the operating system's file system implementation, use : router.Static("/static", "/var/www")

func (*RouterGroup) Use Uses

func (c *RouterGroup) Use(middlewares ...HandlerFunc)

Adds middlewares to the group

type Session Uses

type Session interface {
    Get(key interface{}) interface{}
    Set(key interface{}, val interface{})
    Delete(key interface{})
    Clear()
    AddFlash(value interface{}, vars ...string)
    Flashes(vars ...string) []interface{}
    Options(SessionOptions)
}

Session stores the values and optional configuration for a session.

type SessionOptions Uses

type SessionOptions struct {
    Path     string
    Domain   string
    MaxAge   int
    Secure   bool
    HTTPOnly bool
}

SessionOptions stores configuration for a session or session store.

type SessionStore Uses

type SessionStore interface {
    sessions.Store
    Options(SessionOptions)
}

SessionStore is an interface for custom session stores.

Directories

PathSynopsis
render

Package neko imports 24 packages (graph) and is imported by 6 packages. Updated 2016-07-16. Refresh now. Tools for package owners.