old

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

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

func NewContext

func NewContext(r *http.Request, w http.ResponseWriter) *Context

NewContext 初始化一个Context

func (*Context) BaseContext

func (ctx *Context) BaseContext() context.Context

func (*Context) BindJson

func (ctx *Context) BindJson(obj interface{}) error

func (*Context) BindXml

func (ctx *Context) BindXml(obj interface{}) error

func (*Context) ClientIp

func (ctx *Context) ClientIp() string

func (*Context) Cookie

func (ctx *Context) Cookie(key string) (string, bool)

func (*Context) Cookies

func (ctx *Context) Cookies() map[string]string

cookie

func (*Context) Deadline

func (ctx *Context) Deadline() (deadline time.Time, ok bool)

#region implement context.Context

func (*Context) Done

func (ctx *Context) Done() <-chan struct{}

func (*Context) Err

func (ctx *Context) Err() error

func (*Context) Form

func (ctx *Context) Form(key string) interface{}

func (*Context) FormAll

func (ctx *Context) FormAll() map[string][]string

func (*Context) FormBool

func (ctx *Context) FormBool(key string, def bool) (bool, bool)

func (*Context) FormFloat32

func (ctx *Context) FormFloat32(key string, def float32) (float32, bool)

func (*Context) FormFloat64

func (ctx *Context) FormFloat64(key string, def float64) (float64, bool)

func (*Context) FormInt64

func (ctx *Context) FormInt64(key string, def int64) (int64, bool)

func (*Context) FormStringSlice

func (ctx *Context) FormStringSlice(key string, def []string) ([]string, bool)

func (*Context) FromFile

func (ctx *Context) FromFile(key string) (*multipart.FileHeader, error)

func (*Context) GetRawData

func (ctx *Context) GetRawData() ([]byte, error)

其他格式

func (*Context) GetRequest

func (ctx *Context) GetRequest() *http.Request

func (*Context) GetResponse

func (ctx *Context) GetResponse() http.ResponseWriter

func (*Context) HasTimeout

func (ctx *Context) HasTimeout() bool

func (*Context) Header

func (ctx *Context) Header(key string) (string, bool)

func (*Context) Headers

func (ctx *Context) Headers() map[string][]string

header

func (*Context) Host

func (ctx *Context) Host() string

func (*Context) Html

func (ctx *Context) Html(file string, obj interface{}) IResponse

html 输出

func (*Context) Json

func (ctx *Context) Json(obj interface{}) IResponse

func (*Context) Jsonp

func (ctx *Context) Jsonp(obj interface{}) IResponse

jsonp输出

func (*Context) Method

func (ctx *Context) Method() string

func (*Context) Next

func (ctx *Context) Next() error

func (*Context) Param

func (ctx *Context) Param(key string) interface{}

获取路由参数

func (*Context) ParamBool

func (ctx *Context) ParamBool(key string, def bool) (bool, bool)

func (*Context) ParamFloat32

func (ctx *Context) ParamFloat32(key string, def float32) (float32, bool)

func (*Context) ParamFloat64

func (ctx *Context) ParamFloat64(key string, def float64) (float64, bool)

func (*Context) ParamInt

func (ctx *Context) ParamInt(key string, def int) (int, bool)

#endregion 路由匹配中带的参数 形如 /book/:id

func (*Context) ParamInt64

func (ctx *Context) ParamInt64(key string, def int64) (int64, bool)

func (*Context) ParamString

func (ctx *Context) ParamString(key string, def string) (string, bool)

func (*Context) Query

func (ctx *Context) Query(key string) interface{}

func (*Context) QueryAll

func (ctx *Context) QueryAll() map[string][]string

获取请求地址中所有参数

func (*Context) QueryBool

func (ctx *Context) QueryBool(key string, def bool) (bool, bool)

func (*Context) QueryFloat32

func (ctx *Context) QueryFloat32(key string, def float32) (float32, bool)

func (*Context) QueryFloat64

func (ctx *Context) QueryFloat64(key string, def float64) (float64, bool)

func (*Context) QueryInt

func (ctx *Context) QueryInt(key string, def int) (int, bool)

#region query url

func (*Context) QueryInt64

func (ctx *Context) QueryInt64(key string, def int64) (int64, bool)

func (*Context) QueryString

func (ctx *Context) QueryString(key string, def string) (string, bool)

func (*Context) QueryStringSlice

func (ctx *Context) QueryStringSlice(key string, def []string) ([]string, bool)

func (*Context) Redirect

func (ctx *Context) Redirect(path string) IResponse

重定向

func (*Context) SetCookie

func (ctx *Context) SetCookie(key string, val string, maxAge int, path string, domain string, secure bool, httpOnly bool) IResponse

Cookie

func (*Context) SetHandlers

func (ctx *Context) SetHandlers(handlers []ControllerHandler)

func (*Context) SetHasTimeout

func (ctx *Context) SetHasTimeout()

func (*Context) SetHeader

func (ctx *Context) SetHeader(key string, val string) IResponse

header

func (*Context) SetOkStatus

func (ctx *Context) SetOkStatus() IResponse

设置200

func (*Context) SetParams

func (ctx *Context) SetParams(params map[string]string)

设置参数

func (*Context) SetStatus

func (ctx *Context) SetStatus(code int) IResponse

设置状态码

func (*Context) Text

func (ctx *Context) Text(format string, values ...interface{}) IResponse

func (*Context) Uri

func (ctx *Context) Uri() string

基础信息

func (*Context) Value

func (ctx *Context) Value(key interface{}) interface{}

func (*Context) WriterMux

func (ctx *Context) WriterMux() *sync.Mutex

func (*Context) Xml

func (ctx *Context) Xml(obj interface{}) IResponse

xml输出

type ControllerHandler

type ControllerHandler func(c *Context) error

type Core

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

服务框架核心结构

func NewCore

func NewCore() *Core

初始化框架核心结构

func (*Core) Delete

func (c *Core) Delete(url string, handlers ...ControllerHandler)

对应 Method = DELETE

func (*Core) FindRouteByRequest

func (c *Core) FindRouteByRequest(request *http.Request) *node

匹配路由,如果没有匹配到,返回nil

func (*Core) Get

func (c *Core) Get(url string, handlers ...ControllerHandler)

对应 Method = Get

func (*Core) Group

func (c *Core) Group(prefix string) IGroup

func (*Core) Post

func (c *Core) Post(url string, handlers ...ControllerHandler)

对应 Method = POST

func (*Core) Put

func (c *Core) Put(url string, handlers ...ControllerHandler)

对应 Method = PUT

func (*Core) ServeHTTP

func (c *Core) ServeHTTP(response http.ResponseWriter, request *http.Request)

框架核心结构实现Handler 接口

func (*Core) Use

func (c *Core) Use(middlewares ...ControllerHandler)

注册中间件

type Group

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

func NewGroup

func NewGroup(core *Core, prefix string) *Group

初始化Group

func (*Group) Delete

func (g *Group) Delete(uri string, handlers ...ControllerHandler)

实现Delete方法

func (*Group) Get

func (g *Group) Get(uri string, handlers ...ControllerHandler)

实现Get方法

func (*Group) Group

func (g *Group) Group(uri string) IGroup

func (*Group) Post

func (g *Group) Post(uri string, handlers ...ControllerHandler)

实现Post方法

func (*Group) Put

func (g *Group) Put(uri string, handlers ...ControllerHandler)

实现Put方法

func (*Group) Use

func (g *Group) Use(middlewares ...ControllerHandler)

type IGroup

type IGroup interface {
	Get(string, ...ControllerHandler)
	Post(string, ...ControllerHandler)
	Put(string, ...ControllerHandler)
	Delete(string, ...ControllerHandler)
	Group(prefix string) IGroup
	// 嵌套中间件
	Use(middlewares ...ControllerHandler)
}

type IRequest

type IRequest interface {
	// 请求地址 url 中带的参数
	// 形如: foo.com?a=1&b=bar&c[]=bar
	QueryInt(key string, def int) (int, bool)
	QueryInt64(key string, def int64) (int64, bool)
	QueryFloat64(key string, def float64) (float64, bool)
	QueryFloat32(key string, def float32) (float32, bool)
	QueryBool(key string, def bool) (bool, bool)
	QueryString(key string, def string) (string, bool)
	QueryStringSlice(key string, def []string) ([]string, bool)
	Query(key string) interface{}

	// 路由匹配中带的参数
	// 形如 /book/:id
	ParamInt(key string, def int) (int, bool)
	ParamInt64(key string, def int64) (int64, bool)
	ParamFloat64(key string, def float64) (float64, bool)
	ParamFloat32(key string, def float32) (float32, bool)
	ParamBool(key string, def bool) (bool, bool)
	ParamString(key string, def string) (string, bool)
	Param(key string) interface{}

	// form 表单中带的参数
	FormInt(key string, def int) (int, bool)
	FormInt64(key string, def int64) (int64, bool)
	FormFloat64(key string, def float64) (float64, bool)
	FormFloat32(key string, def float32) (float32, bool)
	FormBool(key string, def bool) (bool, bool)
	FormString(key string, def string) (string, bool)
	FormStringSlice(key string, def []string) ([]string, bool)
	FormFile(key string) (*multipart.FileHeader, error)
	Form(key string) interface{}

	// json body
	BindJson(obj interface{}) error

	// xml body
	BindXml(obj interface{}) error

	// 其他格式
	GetRawData() ([]byte, error)

	// 基础信息
	Uri() string
	Method() string
	Host() string
	ClientIp() string

	// header
	Headers() map[string][]string
	Header(key string) (string, bool)

	// cookie
	Cookies() map[string]string
	Cookie(key string) (string, bool)
}

代表请求包含的方法

type IResponse

type IResponse interface {
	// Json 输出
	Json(obj interface{}) IResponse

	// Jsonp 输出
	Jsonp(obj interface{}) IResponse

	//xml 输出
	Xml(obj interface{}) IResponse

	// html 输出
	Html(template string, obj interface{}) IResponse

	// string
	Text(format string, values ...interface{}) IResponse

	// 重定向
	Redirect(path string) IResponse

	// header
	SetHeader(key string, val string) IResponse

	// Cookie
	SetCookie(key string, val string, maxAge int, path, domain string, secure, httpOnly bool) IResponse

	// 设置状态码
	SetStatus(code int) IResponse

	// 设置 200 状态
	SetOkStatus() IResponse
}

IResponse 代表返回方法

type Tree

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

func NewTree

func NewTree() *Tree

func (*Tree) AddRoute

func (tree *Tree) AddRoute(uri string, handlers []ControllerHandler) error

增加路由节点

/book/list /book/:id (冲突) /book/:id/name /book/:student/age /:user/name /:user/name/:age(冲突)

func (*Tree) FindHandler

func (tree *Tree) FindHandler(uri string) []ControllerHandler

匹配uri

Jump to

Keyboard shortcuts

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