Back to godoc.org
github.com/rocwong/neko

Package neko

v0.0.0-...-2c015f8
Latest Go to latest

The latest major version is .

Published: Jan 30, 2016 | License: MIT | Module: github.com/rocwong/neko

Index

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

func Version() string

type Context

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

func (c *Context) Abort()

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

func (*Context) ClientIP

func (c *Context) ClientIP() string

ClientIP returns more real IP address.

func (*Context) Get

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

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

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

func (*Context) GetCookie

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

GetCookie returns given cookie value from request header.

func (*Context) GetSecureCookie

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

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

func (*Context) Json

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

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

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

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

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

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

func (*Context) Set

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

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

func (*Context) SetBasicSecureCookie

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

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

func (*Context) SetCookie

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

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

SetHeader sets a response header.

func (*Context) SetSecureCookie

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

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

func (*Context) Text

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

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

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

func Classic

func Classic(appName ...string) *Engine

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

func New

func New() *Engine

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

func (*Engine) Run

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

Run run the http server.

func (*Engine) RunTLS

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

Run run the https server.

func (*Engine) ServeHTTP

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

ServeHTTP makes the router implement the http.Handler interface.

func (*Engine) SetCookieSecret

func (m *Engine) SetCookieSecret(secret string)

SetCookieSecret sets global default secure cookie secret.

func (*Engine) Use

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

type HandlerFunc

type HandlerFunc func(*Context)

func Logger

func Logger() HandlerFunc

func Recovery

func Recovery() HandlerFunc

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

type HtmlEngine

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

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

type JSON

type JSON map[string]interface{}

type ResponseWriter

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

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

func (*RouterGroup) Any

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

Any is a shortcut for all request methods

func (*RouterGroup) DELETE

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

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

func (*RouterGroup) GET

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

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

func (*RouterGroup) Group

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

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

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

func (*RouterGroup) Handle

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

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

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

func (*RouterGroup) PATCH

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

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

func (*RouterGroup) POST

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

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

func (*RouterGroup) PUT

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

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

func (*RouterGroup) Static

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

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

Adds middlewares to the group

type Session

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

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

SessionOptions stores configuration for a session or session store.

type SessionStore

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

SessionStore is an interface for custom session stores.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier