fgee

package module
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2020 License: MIT Imports: 12 Imported by: 0

README

Go 使用 fasthttp 实现类 gin 的 Web 框架

原版使用 net/http 实现,地址:https://github.com/leffss/gee

这里使用 github.com/valyala/fasthttp 实现,功能与使用方法一样。

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ReadTimeout  time.Duration = time.Second * 30
	WriteTimeout time.Duration = time.Second * 30
)

Functions

func SetReadTimeout

func SetReadTimeout(second int)

func SetWriteTimeout

func SetWriteTimeout(second int)

Types

type Context

type Context struct {
	// origin objects
	Ctx *fasthttp.RequestCtx
	// request info
	Path   string
	Method string
	Params map[string]string
	// response info
	StatusCode int

	// Keys is a key/value pair exclusively for the context of each request.
	Keys map[string]interface{}
	// contains filtered or unexported fields
}

func (*Context) Cookie

func (c *Context) Cookie(name string) (string, error)

Cookie returns the named cookie provided in the request or ErrNoCookie if not found. And return the named cookie is unescaped. If multiple cookies match the given name, only one cookie will be returned.

func (*Context) Data

func (c *Context) Data(code int, data []byte)

func (*Context) Fail

func (c *Context) Fail(code int, err string)

func (*Context) Get

func (c *Context) Get(key string) (value interface{}, exists bool)

Get returns the value for the given key, ie: (value, true). If the value does not exists it returns (nil, false)

func (*Context) GetHeader

func (c *Context) GetHeader(key string) string

func (*Context) HTML

func (c *Context) HTML(code int, name string, data interface{})

HTML template render refer https://golang.org/pkg/html/template/

func (*Context) JSON

func (c *Context) JSON(code int, obj interface{})

func (*Context) MustGet

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

MustGet returns the value for the given key if it exists, otherwise it panics.

func (*Context) Next

func (c *Context) Next()

func (*Context) Param

func (c *Context) Param(key string) string

func (*Context) PostForm

func (c *Context) PostForm(key string) string

func (*Context) PostJson

func (c *Context) PostJson() string

func (*Context) Query

func (c *Context) Query(key string) string

func (*Context) Set

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

Set is used to store a new key/value pair exclusively for this context. It also lazy initializes c.Keys if it was not used previously.

func (*Context) SetCookie

func (c *Context) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)

SetCookie adds a Set-Cookie header to the ResponseWriter's headers. The provided cookie must have a valid Name. Invalid cookies may be silently dropped.

func (*Context) SetHeader

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

func (*Context) Status

func (c *Context) Status(code int)

func (*Context) String

func (c *Context) String(code int, format string, values ...interface{})

type Engine

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

Engine implement the interface of ServeHTTP

func Default

func Default() *Engine

Default use Logger & Recovery middleware

func New

func New() *Engine

New is the constructor of gee.Engine

func (*Engine) LoadHTMLGlob

func (engine *Engine) LoadHTMLGlob(pattern string)

func (*Engine) Run

func (engine *Engine) Run(addr string) (err error)

Run defines the method to start a http server

func (*Engine) RunTLS

func (engine *Engine) RunTLS(addr, ca, key string) (err error)

func (*Engine) ServeHTTP

func (engine *Engine) ServeHTTP(fastCtx *fasthttp.RequestCtx)

func (*Engine) SetFuncMap

func (engine *Engine) SetFuncMap(funcMap template.FuncMap)

custom render function

func (*Engine) Shutdown

func (engine *Engine) Shutdown() (err error)

type H

type H map[string]interface{}

type HandlerFunc

type HandlerFunc func(*Context)

HandlerFunc defines the request handler used by gee

func Logger

func Logger() HandlerFunc

func Recovery

func Recovery() HandlerFunc

type RouterGroup

type RouterGroup struct {
	// contains filtered or unexported fields
}

Engine implement the interface of ServeHTTP

func (*RouterGroup) Any

func (group *RouterGroup) Any(pattern string, handler HandlerFunc)

Any registers a route that matches all the HTTP methods. GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS, TRACE.

func (*RouterGroup) DELETE

func (group *RouterGroup) DELETE(pattern string, handler HandlerFunc)

DELETE defines the method to add DELETE request

func (*RouterGroup) GET

func (group *RouterGroup) GET(pattern string, handler HandlerFunc)

GET defines the method to add GET request

func (*RouterGroup) Group

func (group *RouterGroup) Group(prefix string) *RouterGroup

Group is defined to create a new RouterGroup remember all groups share the same Engine instance

func (*RouterGroup) HEAD

func (group *RouterGroup) HEAD(pattern string, handler HandlerFunc)

HEAD defines the method to add HEAD request

func (*RouterGroup) OPTIONS

func (group *RouterGroup) OPTIONS(pattern string, handler HandlerFunc)

OPTIONS defines the method to add OPTIONS request

func (*RouterGroup) PATCH

func (group *RouterGroup) PATCH(pattern string, handler HandlerFunc)

PATCH defines the method to add PATCH request

func (*RouterGroup) POST

func (group *RouterGroup) POST(pattern string, handler HandlerFunc)

POST defines the method to add POST request

func (*RouterGroup) PUT

func (group *RouterGroup) PUT(pattern string, handler HandlerFunc)

PUT defines the method to add PUT request

func (*RouterGroup) Static

func (group *RouterGroup) Static(relativePath string, root string)

serve static files

func (*RouterGroup) TRACE

func (group *RouterGroup) TRACE(pattern string, handler HandlerFunc)

TRACE defines the method to add TRACE request

func (*RouterGroup) Use

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

Use is defined to add middleware to the group

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL