framework

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: MIT Imports: 15 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

func (*Context) BaseContext

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

func (*Context) BinJson

func (ctx *Context) BinJson(obj any) error

将body文本解析到obj结构体中

func (*Context) BindXml

func (ctx *Context) BindXml(obj any) error

xml body

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)

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) any

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) FormFile

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

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) FormInt

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

form post

func (*Context) FormInt64

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

func (*Context) FormString

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

func (*Context) FormStringSlice

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

func (*Context) GetRawData

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

其他格式

func (*Context) GetRequst

func (ctx *Context) GetRequst() *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 any) IResponse

html输出

func (*Context) Json

func (ctx *Context) Json(obj any) IResponse

func (*Context) Jsonp

func (ctx *Context) Jsonp(obj any) IResponse

func (*Context) Method

func (ctx *Context) Method() string

func (*Context) Next

func (ctx *Context) Next() error

核心函数,调用context的下一个函数

func (*Context) Param

func (ctx *Context) Param(key string) any

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)

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) any

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)

获取Int类型的请求参数

func (*Context) QueryInt64

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

func (*Context) QueryString

func (ctx *Context) QueryString(key, 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, domain string, secure, httpOnly bool) IResponse

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

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 ...any) IResponse

string

func (*Context) Uri

func (ctx *Context) Uri() string

基础信息

func (*Context) Value

func (ctx *Context) Value(key any) any

func (*Context) WriterMux

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

func (*Context) Xml

func (ctx *Context) Xml(obj any) IResponse

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, handler ...ControllerHandler)

匹配DELETE方法, 增加路由规则

func (*Core) FindRouteNodeByRequest

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

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

func (*Core) Get

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

匹配GET方法, 增加路由规则

func (*Core) Group

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

路由组

func (*Core) Post

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

匹配POST方法, 增加路由规则

func (*Core) Put

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

匹配PUT方法, 增加路由规则

func (*Core) ServeHTTP

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

所有请求都进入这个函数, 这个函数负责路由分发

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

实现 Group 方法

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 {
	// 实现HttpMethod方法
	Get(string, ...ControllerHandler)
	Post(string, ...ControllerHandler)
	Put(string, ...ControllerHandler)
	Delete(string, ...ControllerHandler)

	// 实现嵌套group
	Group(string) IGroup

	// 嵌套中间件
	Use(middlewares ...ControllerHandler)
}

IGroup 代表前缀分组

type IResponse

type IResponse interface {
	// json输出
	Json(obj any) IResponse

	// jsonp输出
	Jsonp(obj any) IResponse

	// xml输出
	Xml(obj any) IResponse

	// html输出
	Html(file string, obj any) IResponse

	// string
	Text(format string, values ...any) 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
}

type IRquest

type IRquest interface {
	// 请求地址url中带的参数
	// 形如: foo.com?a=1&b=bar&c[]=bar
	QueryInt(key string, def int) (int, bool)
	QueryInt64(key string, def int64) (int64, bool)
	QueryFloat32(key string, def float32) (float32, bool)
	QueryFloat64(key string, def float64) (float64, 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) any

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

	// form表单中带的参数
	FormInt(key string, def int) (int, bool)
	FormInt64(key string, def int64) (int64, bool)
	FormFloat32(key string, def float32) (float32, bool)
	FormFloat64(key string, def float64) (float64, 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) any

	// json body
	BindJson(obj any) error

	// xml body
	BindXml(obj any) 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(string) (string, bool)
}

代表请求包含的方法

type Tree

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

func NewTree

func NewTree() *Tree

func (*Tree) AddRouter

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

func (*Tree) FindHandler

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

匹配uri

Directories

Path Synopsis
gin module

Jump to

Keyboard shortcuts

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