fastserver

package
v0.0.0-...-ecf5411 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2022 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentTypeUrlEncode       = "application/x-www-form-urlencoded"
	ContentTypeApplicationJson = "application/json"
	ContentTypeNone            = "-"
)

Variables

This section is empty.

Functions

func DefaultRecover

func DefaultRecover(c *Context)

recover handler 兜底,防止业务逻辑出现panic导致服务直接不可用

Types

type Api

type Api struct {
	Name               string
	Method             string
	Route              string
	ContentType        string
	Desc               string
	RequestModel       func() interface{} // request model factory,
	RequestExample     interface{}        // this will be part of request example of api doc
	HandleFunc         HandlerFunc        // request handler ,if  null ,Handler will be use
	NotValidateRequest bool
	Handler            interface{} // type must be func(*fastserver.Context,*struct{})(int,*struct{}) or  func(*fastserver.Context})(int,*struct{})
	ResponseExample    interface{} // this will be part of response example of api doc
	// contains filtered or unexported fields
}

func (*Api) Handle

func (a *Api) Handle() Handler

type ApiGroup

type ApiGroup struct {
	Docs []*Document

	ServiceName string
	// contains filtered or unexported fields
}

func NewApiGroup

func NewApiGroup(g *RouterGroup, apis []*Api) *ApiGroup

func (*ApiGroup) Document

func (a *ApiGroup) Document() Handler

func (*ApiGroup) WriteDocTo

func (a *ApiGroup) WriteDocTo(tlp string, w io.Writer) error

type Context

type Context struct {
	FastCtx *fasthttp.RequestCtx

	Path   string // 由于是从fasthttp 里面取过来的,不能够在其他的协程中使用
	Method string

	Params     Params
	RequestURI string
	// contains filtered or unexported fields
}

func (*Context) Abort

func (c *Context) Abort()

func (*Context) AbortWithData

func (c *Context) AbortWithData(status int, data []byte)

func (*Context) AbortWithStatusJson

func (c *Context) AbortWithStatusJson(status int, o interface{}) error

func (*Context) Bind

func (c *Context) Bind(api *Api, model interface{}) error

func (*Context) ClientIp

func (c *Context) ClientIp() net.IP

func (*Context) ClientProxyIP

func (c *Context) ClientProxyIP() string

func (*Context) GetRequestHeader

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

func (*Context) GetUserValue

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

func (*Context) Next

func (c *Context) Next()

func (*Context) Redirect

func (c *Context) Redirect(uri string, statusCode int)

func (*Context) Run

func (c *Context) Run()

func (*Context) SetResponseHeader

func (c *Context) SetResponseHeader(k, v string)

func (*Context) SetUserValue

func (c *Context) SetUserValue(key string, val interface{})

func (*Context) StdHttpRequest

func (c *Context) StdHttpRequest() *http.Request

获取标准的http request

func (*Context) StdResponseWriter

func (c *Context) StdResponseWriter() http.ResponseWriter

获取标准的 http responseWriter

type DocParam

type DocParam struct {
	Name        string
	Type        string
	Required    string
	Default     string
	Desc        string
	Constraints string
	From        string
}

type Document

type Document struct {
	Name        string
	Method      string
	Route       string
	Desc        string
	RespExample string
	Params      []*DocParam
	RespParams  []*DocParam
	Example     string
	ContentType string
}

type H

type H map[string]interface{}

type Handler

type Handler func(ctx *Context)

type HandlerFunc

type HandlerFunc func(ctx *Context, model interface{}) (code int, resp interface{})

type HandlersChain

type HandlersChain []Handler

func (HandlersChain) Last

func (c HandlersChain) Last() Handler

type Message

type Message struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type Param

type Param struct {
	Key   string
	Value string
}

Param is a single URL parameter, consisting of a key and a value.

type Params

type Params []Param

Params is a Param-slice, as returned by the router. The slice is ordered, the first URL parameter is also the first slice value. It is therefore safe to read values by the index.

func (Params) ByName

func (ps Params) ByName(name string) (va string)

ByName returns the value of the first Param which key matches the given name. If no matching Param is found, an empty string is returned.

func (Params) Get

func (ps Params) Get(name string) (string, bool)

Get returns the value of the first Param which key matches the given name. If no matching Param is found, an empty string is returned.

type RouterGroup

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

func (*RouterGroup) Any

func (r *RouterGroup) Any(path string, handler Handler)

func (*RouterGroup) DELETE

func (r *RouterGroup) DELETE(path string, handler Handler)

func (*RouterGroup) GET

func (r *RouterGroup) GET(path string, handler Handler)

func (*RouterGroup) Group

func (r *RouterGroup) Group(pth string) *RouterGroup

创建一个group,可以构建新的拦截器链路,新的group 会继承父拦截器(handler)

func (*RouterGroup) HEAD

func (r *RouterGroup) HEAD(path string, handler Handler)

func (*RouterGroup) Method

func (r *RouterGroup) Method(method string, pth string, handler Handler)

func (*RouterGroup) OPTION

func (r *RouterGroup) OPTION(path string, handler Handler)

func (*RouterGroup) PATCH

func (r *RouterGroup) PATCH(path string, handler Handler)

func (*RouterGroup) POST

func (r *RouterGroup) POST(path string, handler Handler)

func (*RouterGroup) PUT

func (r *RouterGroup) PUT(path string, handler Handler)

func (*RouterGroup) RegisterApis

func (r *RouterGroup) RegisterApis(apis []*Api) *ApiGroup

func (*RouterGroup) Use

func (r *RouterGroup) Use(handlers ...Handler)

添加拦截器(handlers)

type Server

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

http server 基于fastHttp 封装路由功能 路由部分参考gin 的路由树,支持path 参数

func NewServer

func NewServer() *Server

func (*Server) Currency

func (s *Server) Currency() int64

func (*Server) NotFound

func (r *Server) NotFound(handler Handler)

func (*Server) Run

func (s *Server) Run(addr string, reusepor bool) (err error)

func (*Server) RunFork

func (s *Server) RunFork(addr string, resuport bool) error

func (*Server) RunPFork

func (s *Server) RunPFork(addr string, reusePort bool) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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