web

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Package web 框架的基本功能包,此包包含了搭建服务的基础功能

Package web web 包是Tigo框架的基础包,内部封装了Handler、http context、middleware、application、session等相关模块的操作。

使用Tigo创建的服务,可以裸起,也可以通过endless、overseer等进行平滑启动。 使用endless平滑启动的示例如下

Basic Example:

func main() {
    application := web.Application{UrlPatterns: urlRouter}
    application.EndlessStart()
}

---------------------------------------------------------------------------------------------------------------------

使用overseer平滑启动示例如下,`fetcher.File`是你的Tigo项目的二进制可执行文件的路径,Overseer按照Interval设置的时间轮询该文件是否更新, 更新后会进行平滑重启。

Basic Example:

	func main() {
     application := web.Application{UrlPatterns: urlRouter}
     application.OverseerStart(&fetcher.File{
         Path:     "path/to/your/app-file",
         Interval: 1 * time.Second,
     })
	}

---------------------------------------------------------------------------------------------------------------------

通过中间件可以设置context上下文,在中间件中设置`context.Context`后,可以在handler中获取,只要能获取`http.Request`,就可以从中获取在 中间件中设置的`context.Context`。示例如下:

Basic Example:

func Authorize(w *http.ResponseWriter, r *http.Request) bool {
	cxt := context.WithValue(r.Context(), "keyFat", "valueJu")
	*r = *r.WithContext(cxt)
	return true
}

func (p *PingHandler) Post() {
	valueInCtx := p.Request.Context().Value("keyFat")
	p.ResponseAsText(valueInCtx)
}

Package web Copyright 2018 The Tigo Authors. All rights reserved.

Package web Copyright 2018 The Tigo Authors. All rights reserved.

Package web Copyright 2018 The Tigo Authors. All rights reserved.

Index

Constants

View Source
const (
	FnInitHandler     = "InitHandler"
	FnPassJson        = "PassJson"
	FnBeforeRequest   = "BeforeRequest"
	FnTeardownRequest = "TeardownRequest"
)

定义函数名

View Source
const Version = "2.0.0"

Variables

View Source
var SessionCookieName = "TigoSessionId" // session的cookie名称

Functions

func Decrypt

func Decrypt(src []byte, key []byte) ([]byte, error)

Decrypt 方法会先对原始数据进行base64解码,然后根据key进行解密, 解密失败则返回空

  • src: 加密后的数据
  • key: 加密时使用的密钥

func Encrypt

func Encrypt(src []byte, key []byte) (string, error)

Encrypt 方法用来根据key对原始数据进行加密,并将加密结果进行base64编码, 加密失败则返回空

  • src: 原信息
  • key: 加密密钥

func GetTagValue

func GetTagValue(field reflect.StructField, tagKey string) (tagValue string)

GetTagValue 根据结构体字段获取tag标签的值

  • field: 通过反射获取的字段名称
  • tagKey: tag标签的key

func HttpContextLogMiddleware

func HttpContextLogMiddleware(next http.HandlerFunc) http.HandlerFunc

HttpContextLogMiddleware 记录一个http请求响应时间的中间件

func InitGlobalConfig

func InitGlobalConfig(configPath string)

InitGlobalConfig 方法用来初始化全局变量

func InitGlobalConfigWithObj

func InitGlobalConfigWithObj(config GlobalConfig)

InitGlobalConfigWithObj 可使用TigoWeb.GlobalConfig的实例进行初始化全局变量

func InternalServerErrorMiddleware

func InternalServerErrorMiddleware(next http.HandlerFunc) http.HandlerFunc

InternalServerErrorMiddleware 用来处理控制层出现的异常的中间件

func MD5

func MD5(origin string) string

MD5 取字符串的md5值

  • origin: 原始字符串的值

func MD5m16

func MD5m16(origin string) string

MD5m16 获取一个长度只有16位的md5值

  • origin: 原始字符串的值

func MethodEnum

func MethodEnum(httpMethod string) string

MethodEnum 根据http请求方式获取对应的函数名

  • httpMethod: http请求方式

func UrlDecode

func UrlDecode(value string) (result string)

UrlDecode 对一个字符串进行url解码

func UrlEncode

func UrlEncode(value string) (result string)

UrlEncode 对一个字符串进行url编码

func VoidFuncCall

func VoidFuncCall(instance reflect.Value, funcName string, funcParams ...reflect.Value)

VoidFuncCall 调用某个指定的方法,通过反射获取某个变量的值,然后通过传入的方法名,调用这个变量中的方法; 这个方法只适用于没有入参,且无返回值的函数调用

  • instance: 实例
  • funcName: 需要调用的方法名
  • funcParams: 调用函数所需要的参数

Types

type Application

type Application struct {
	IPAddress   string    // IP地址
	Port        int       // 端口
	UrlPatterns []Pattern // url路由配置
	ConfigPath  string    // 全局配置
	// contains filtered or unexported fields
}

Application web容器

func (*Application) EndlessStart

func (application *Application) EndlessStart()

EndlessStart 使用endless进行平滑启动

func (*Application) InitApp

func (application *Application) InitApp()

InitApp 初始化配置信息及路由

func (*Application) Listen

func (application *Application) Listen(port int)

Listen 端口监听

func (*Application) MountFileServer

func (application *Application) MountFileServer(dir string, uris ...string)

MountFileServer 挂载文件服务

  • dir 本地文件地址
  • uris 需要挂载的URI,只支持至多一个URI,输入多个则只取第一个,默认为/路径,URI尽量以/结尾,这样兼容性高一些,比如: application.MountFileServer("/path/to/files", "/files/", "/", "/your/uri/")

func (*Application) OverseerStart

func (application *Application) OverseerStart(fc fetcher.Interface)

OverseerStart 使用overseer进行平滑启动

  • fc: overseer包中的fetcher接口,包括file、http、GitHub等

func (*Application) Run

func (application *Application) Run()

Run 服务启动函数

func (*Application) StartSession

func (application *Application) StartSession(sessionInterface SessionInterface, sessionCookieName string)

StartSession 设置session,此函数只提供session操作的接口,以便于第三方session插件嵌入。

type BaseHandler

type BaseHandler struct {
	ResponseWriter http.ResponseWriter
	Request        *http.Request
	JsonParams     map[string]interface{}
	// contains filtered or unexported fields
}

BaseHandler 是Handler的基础类,开发者开发的handler继承此类

func (*BaseHandler) BeforeRequest

func (baseHandler *BaseHandler) BeforeRequest()

BeforeRequest 在每次响应HTTP请求之前执行此函数

func (*BaseHandler) CheckFormBinding

func (baseHandler *BaseHandler) CheckFormBinding(obj interface{}) error

CheckFormBinding 检查提交的form是否符合要求

func (*BaseHandler) CheckJsonBinding

func (baseHandler *BaseHandler) CheckJsonBinding(obj interface{}) error

CheckJsonBinding 检查提交的json是否符合要求

func (*BaseHandler) CheckParamBinding

func (baseHandler *BaseHandler) CheckParamBinding(obj interface{}) error

CheckParamBinding 检查提交的参数是否符合要求

func (*BaseHandler) CheckUrlParamBinding

func (baseHandler *BaseHandler) CheckUrlParamBinding(obj interface{}) error

CheckUrlParamBinding 检查url上传递的参数是否符合要求

func (*BaseHandler) ClearAllCookie

func (baseHandler *BaseHandler) ClearAllCookie()

ClearAllCookie 清除本次请求当前path下所有的cookie

func (*BaseHandler) ClearCookie

func (baseHandler *BaseHandler) ClearCookie(name string)

ClearCookie 清除本次请求当前path下的指定的cookie

  • name: 需要清楚的cookie的name

func (*BaseHandler) ClearSession

func (baseHandler *BaseHandler) ClearSession(key string)

ClearSession 根据key清除对应的session值

func (*BaseHandler) Connect

func (baseHandler *BaseHandler) Connect()

Connect 方法

func (*BaseHandler) DelSession

func (baseHandler *BaseHandler) DelSession()

DelSession 删除所有的session值

func (*BaseHandler) Delete

func (baseHandler *BaseHandler) Delete()

Delete 方法

func (*BaseHandler) DumpHttpRequestMsg

func (baseHandler *BaseHandler) DumpHttpRequestMsg(logLevel int)

DumpHttpRequestMsg 获取http请求报文,根据logLevel值进行不同的输出

  • 1: 将http报文输出到trace级别日志中
  • 2: 将http报文输出到info级别日志中
  • 3: 将http报文输出到warning级别日志中
  • 4: 将http报文输出到error级别日志中
  • others: 将http报文输出到控制台

func (*BaseHandler) Get

func (baseHandler *BaseHandler) Get()

Get 方法

func (*BaseHandler) GetBody

func (baseHandler *BaseHandler) GetBody() []byte

GetBody 获取HTTP报文体

func (*BaseHandler) GetCookie

func (baseHandler *BaseHandler) GetCookie(name string) (value string)

GetCookie 获取cookie值,如果获取失败则返回空字符串

  • name: cookie的name

func (*BaseHandler) GetCookieObject

func (baseHandler *BaseHandler) GetCookieObject(name ...string) (Cookie, error)

GetCookieObject 获取cookie对象,多参数输入,参数如下:

  • 无参数:默认cookieName为空字符串
  • 一个参数:传入的参数为cookieName
  • 多个参数:传入的第一个参数为cookieName,第二个参数为加密/解密cookie所用的Key,此时认为cookie是需要进行加密/解密处理的

func (*BaseHandler) GetCtxVal

func (baseHandler *BaseHandler) GetCtxVal(key string) interface{}

GetCtxVal 从上下文获取值

func (*BaseHandler) GetHeader

func (baseHandler *BaseHandler) GetHeader(name string) (value string)

GetHeader 获取header

func (*BaseHandler) GetJsonValue

func (baseHandler *BaseHandler) GetJsonValue(key string) interface{}

GetJsonValue 根据key获取对应的参数值,解析json数据,返回对应的value

func (*BaseHandler) GetParameter

func (baseHandler *BaseHandler) GetParameter(key string) (value *ReqParams)

GetParameter 根据key获取对应的参数值

  • 如果Content-Type是application/json,则直接从http的body中解析出key对应的value
  • 否则,根据key直接获取value

func (*BaseHandler) GetPathParam

func (baseHandler *BaseHandler) GetPathParam(key string) (value PathParam)

GetPathParam 根据key获取Url上的参数

func (*BaseHandler) GetPathParamStr

func (baseHandler *BaseHandler) GetPathParamStr(key string) string

GetPathParamStr 根据key获取Url上的参数

func (*BaseHandler) GetSecureCookie

func (baseHandler *BaseHandler) GetSecureCookie(name string, key ...string) (value string)

GetSecureCookie 获取加密cookie值,如果获取失败则返回空

  • name: cookie的name
  • key: cookie加密用的key

func (*BaseHandler) GetSession

func (baseHandler *BaseHandler) GetSession(key string, value interface{}) (err error)

GetSession 根据key获取session值

func (*BaseHandler) Head

func (baseHandler *BaseHandler) Head()

Head 方法

func (*BaseHandler) InitHandler

func (baseHandler *BaseHandler) InitHandler(responseWriter http.ResponseWriter, request *http.Request)

InitHandler 初始化Handler的方法

func (*BaseHandler) Move

func (baseHandler *BaseHandler) Move(url string, expire ...time.Time)

Move 向客户端暂时移动一个地址

  • url: 指定客户端要移动的目标地址
  • expire: 过期时间

func (*BaseHandler) MovePermanently

func (baseHandler *BaseHandler) MovePermanently(url string)

MovePermanently 向客户端永久性移动一个地址

  • url: 指定客户端要移动的目标地址

func (*BaseHandler) Options

func (baseHandler *BaseHandler) Options()

Options 方法

func (*BaseHandler) PassJson

func (baseHandler *BaseHandler) PassJson()

PassJson 用来解析json中的值

func (*BaseHandler) Post

func (baseHandler *BaseHandler) Post()

Post 方法

func (*BaseHandler) Put

func (baseHandler *BaseHandler) Put()

Put 方法

func (*BaseHandler) Redirect

func (baseHandler *BaseHandler) Redirect(url string, expire ...time.Time)

Redirect 向客户端暂时重定向一个地址

  • url: 重定向的地址
  • expire: 过期时间

func (*BaseHandler) RedirectPermanently

func (baseHandler *BaseHandler) RedirectPermanently(url string)

RedirectPermanently 向客户端永久重定向一个地址

  • url: 重定向的地址

func (*BaseHandler) RedirectTo

func (baseHandler *BaseHandler) RedirectTo(url string, status int, expire ...time.Time)

RedirectTo 自定义重定向

  • url: 重定向的url
  • status: http状态码
  • expire: 过期时间

func (*BaseHandler) Render

func (baseHandler *BaseHandler) Render(data interface{}, templates ...string)

Render 渲染模板,返回数据 参数解析如下:

  • data:表示传入的待渲染的数据
  • templates:表示模板文件的路径,接受多个模板文件

func (*BaseHandler) Response

func (baseHandler *BaseHandler) Response(result ...interface{})

Response 向客户端响应一个结果

func (*BaseHandler) ResponseAsHtml

func (baseHandler *BaseHandler) ResponseAsHtml(result string, charset ...string)

ResponseAsHtml 向客户端响应一个html结果,默认字符集为utf-8

  • result: 相应的结果
  • charset: 字符集,默认utf-8

func (*BaseHandler) ResponseAsJson

func (baseHandler *BaseHandler) ResponseAsJson(response interface{}, charset ...string)

ResponseAsJson 向客户端响应一个Json结果,默认字符集为utf-8

  • response: 需要响应给客户端的数据
  • charset: 数据集,默认utf-8编码

func (*BaseHandler) ResponseAsText

func (baseHandler *BaseHandler) ResponseAsText(result string)

ResponseAsText 向客户端响应一个Text结果

  • response: 需要返回的文本内容

func (*BaseHandler) ResponseFmt

func (baseHandler *BaseHandler) ResponseFmt(format string, values ...interface{})

ResponseFmt 向客户端响应一个字符串,支持format格式化字符串

  • format: 格式化母串
  • values: 返回的值

func (*BaseHandler) ResponseWithFilter

func (baseHandler *BaseHandler) ResponseWithFilter(filter interface{}, conn *gorm.DB, model interface{})

ResponseWithFilter 通过filter返回请求结果,目前只会解析url上传的参数,当前只支持Get请求。

  • filter: 过滤器对象,不要传指针和引用
  • conn: 数据库的链接

func (*BaseHandler) ServerError

func (baseHandler *BaseHandler) ServerError(err error)

ServerError 将服务器端发生的错误返回给客户端

func (*BaseHandler) SetAdvancedCookie

func (baseHandler *BaseHandler) SetAdvancedCookie(name string, value string, attrs ...string)

SetAdvancedCookie 设置cookie

  • name cookie的名称
  • value cookie的value
  • attrs cookie的其他属性值,示例如下:
  • "path={{string}}" 设置cookie的有效作用地址
  • "domain={{string}}" 设置cookie的作用域
  • "raw={{string}}" 设置cookie的raw值
  • "maxAge={{int}}" 设置cookie的MaxAge,表示未指定“Max-Age”属性,表示现在删除cookie,相当于'Max-Age:0',表示Max-Age属性存在并以秒为单位给出
  • "expires={{int}}" 设置cookie的过期时间,按秒计算
  • "secure={{bool}}" 设置cookie是否只限于加密传输
  • "httpOnly={{bool}}" 设置cookie是否只限于http/https传输
  • "isSecurity={{bool}}" 设置cookie是否要进行加密

func (*BaseHandler) SetCookie

func (baseHandler *BaseHandler) SetCookie(name string, value string)

SetCookie 设置cookie SetCookie未设置cookie的domain及path,此cookie仅对当前路径有效,设置其他路径cookie可参考SetAdvancedCookie

  • name: cookie的name
  • value: cookie的值

func (*BaseHandler) SetCookieObject

func (baseHandler *BaseHandler) SetCookieObject(cookie Cookie)

SetCookieObject 设置高级cookie选项

  • cookie: 要设置的cookie对象

func (*BaseHandler) SetCtxVal

func (baseHandler *BaseHandler) SetCtxVal(key string, val interface{})

SetCtxVal 在上下文中设置值

  • demo请查看源代码中的注释

func (*BaseHandler) SetHeader

func (baseHandler *BaseHandler) SetHeader(name string, value string)

SetHeader 设置header

func (*BaseHandler) SetSecureCookie

func (baseHandler *BaseHandler) SetSecureCookie(name string, value string, key ...string)

SetSecureCookie 设置加密cookie SetSecureCookie未设置cookie的domain及path,此cookie仅对当前路径有效,设置其他路径cookie可参考SetAdvancedCookie

func (*BaseHandler) SetSession

func (baseHandler *BaseHandler) SetSession(key string, value interface{}) (err error)

SetSession 根据key设置session值

  • key: session对应的键
  • value: session的值

func (*BaseHandler) TeardownRequest

func (baseHandler *BaseHandler) TeardownRequest()

TeardownRequest 在每次响应HTTP请求之后执行此函数

func (*BaseHandler) ToJson

func (baseHandler *BaseHandler) ToJson(response interface{}) (result []byte)

ToJson 将对象转化为Json字符串,转换失败则返回空字符串。 传入参数Response为一个interface,必须有成员函数Print。

  • response: 需要转换成json的实例

func (*BaseHandler) ToJsonStr

func (baseHandler *BaseHandler) ToJsonStr(response interface{}) (result string)

ToJsonStr 将对象转化为Json字符串,转换失败则返回空字符串。 传入参数Response为一个interface,必须有成员函数Print。

  • response: 需要转换成json的实例

func (*BaseHandler) Trace

func (baseHandler *BaseHandler) Trace()

Trace 方法

func (*BaseHandler) UrlDecode

func (baseHandler *BaseHandler) UrlDecode(value string) string

UrlDecode 对值进行url解码

func (*BaseHandler) UrlEncode

func (baseHandler *BaseHandler) UrlEncode(value string) string

UrlEncode 对值进行url编码

type Cookie struct {
	Name  string
	Value string

	IsSecurity  bool   // 是否对cookie值进行加密
	SecurityKey string // 加密cookie用到的key

	Path       string    // 可选
	Domain     string    // 可选
	Expires    time.Time // 可选
	RawExpires string    // 只有在读取Cookie时有效

	// MaxAge=0 表示未指定“Max-Age”属性
	// MaxAge<0 表示现在删除cookie,相当于'Max-Age:0'
	// MaxAge>0 表示Max-Age属性存在并以秒为单位给出
	MaxAge   int
	Secure   bool
	HttpOnly bool
	Raw      string
	Unparsed []string // 原始文本中未解析的属性值
}

Cookie 是自定义Cookie结构体,可参看http.Cookie

func (*Cookie) ConvertFromHttpCookie

func (cookie *Cookie) ConvertFromHttpCookie(httpCookie http.Cookie)

ConvertFromHttpCookie 将http/Cookie转换为Cookie

func (*Cookie) GetCookieDecodeValue

func (cookie *Cookie) GetCookieDecodeValue() (result string)

GetCookieDecodeValue 获取cookie解密值

  • IsSecurity如果设置为false,则返回原始值
  • IsSecurity如果设置为true,则返回加密后的值

如果解密失败,则抛出异常

func (*Cookie) GetCookieEncodeValue

func (cookie *Cookie) GetCookieEncodeValue() (result string)

GetCookieEncodeValue 获取cookie加密值

  • IsSecurity如果设置为false,则返回原始值
  • IsSecurity如果设置为true,则返回加密后的值

如果加密失败,则抛出异常

func (*Cookie) SetSecurityKey

func (cookie *Cookie) SetSecurityKey(key string)

SetSecurityKey 为Cookie设置SecurityKey

func (*Cookie) ToHttpCookie

func (cookie *Cookie) ToHttpCookie() http.Cookie

ToHttpCookie 转换为http/Cookie对象

type GlobalConfig

type GlobalConfig struct {
	IP       string          `json:"ip"`       // IP地址
	Port     int             `json:"port"`     // 端口
	Cert     string          `json:"cert"`     // https证书路径
	CertKey  string          `json:"cert_key"` // https密钥路径
	Cookie   string          `json:"cookie"`   // cookie加密解密的密钥
	Template string          `json:"template"` // 模板文件所在文件夹的路径
	Log      logger.LogLevel `json:"log"`      // log相关属性配置
}

GlobalConfig 全局配置对象

func (*GlobalConfig) Init

func (globalConfig *GlobalConfig) Init(configPath string)

Init 根据配置文件初始化全局配置变量

type HttpResponseWriter

type HttpResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

HttpResponseWriter Http响应写入器,用于在中间件中修改http响应报文

func (*HttpResponseWriter) GetStatus

func (httpResponseWriter *HttpResponseWriter) GetStatus() int

GetStatus 获取Http状态码

func (*HttpResponseWriter) WriteHeader

func (httpResponseWriter *HttpResponseWriter) WriteHeader(code int)

WriteHeader 设置Http状态码

type Middleware

type Middleware func(*http.ResponseWriter, *http.Request) bool

Middleware Tigo的中间件类型,函数返回值true表示http请求继续处理,false表示请求结束,不再往下处理

type PathParam

type PathParam string

func (PathParam) ToBool

func (p PathParam) ToBool() bool

ToBool 将从url路径中获取参数转换为布尔型

func (PathParam) ToFloat

func (p PathParam) ToFloat() (float64, error)

ToFloat 将url路径中的参数转换为浮点型

func (PathParam) ToInt

func (p PathParam) ToInt() (int, error)

ToInt 将url路径中的参数转换成整型

func (PathParam) ToStr

func (p PathParam) ToStr() string

ToStr 将url路径中的参数转换为字符串型

type Pattern

type Pattern struct {
	Url        string
	Handler    interface{}
	Middleware []Middleware
}

Pattern 路由对象

type ReqParams

type ReqParams struct {
	Value interface{}
}

ReqParams 请求参数结构体

func (*ReqParams) To

func (jsonParam *ReqParams) To(result interface{})

To 将json中的参数值转换为目标对象

func (*ReqParams) ToBool

func (jsonParam *ReqParams) ToBool(defaultValue ...bool) bool

ToBool 将json中的参数值转换为bool

func (*ReqParams) ToFloat64

func (jsonParam *ReqParams) ToFloat64() float64

ToFloat64 将json中解析出的参数格式化为float64类型,失败则返回0

func (*ReqParams) ToInt64

func (jsonParam *ReqParams) ToInt64() int64

ToInt64 将json中解析出来的参数格式化为int64类型,失败则返回0

func (*ReqParams) ToString

func (jsonParam *ReqParams) ToString() string

ToString 将json中解析出的参数格式化为string类型,失败则返回空字符串

type Response

type Response interface {
	Print()
}

Response 响应给客户端的interface,用户自定义实现

type Session

type Session interface {
	// Set 设置session值,设置失败返回error
	Set(key string, value interface{}) error
	// Get 获取session值,获取失败返回error
	Get(key string, value interface{}) error
	// Delete 删除session
	Delete(key string)
	// SessionId 获取session id
	SessionId() string
}

Session session接口,通过该类型的实例进行session的增删改查。

type SessionInterface

type SessionInterface interface {
	// NewSessionManager 新建一个SessionManager
	NewSessionManager() SessionManager
}

SessionInterface Tigo的session接口,第三方需要自定session底层的实现,每个SessionInterface必须包含NewSessionManager()函数。 不想自己实现的可以看看这个插件,直接引入就能用。https://github.com/karldoenitz/tission

type SessionManager

type SessionManager interface {
	// GenerateSession 生成session
	GenerateSession(expire int) Session
	// GetSessionBySid 根据session id获取session
	GetSessionBySid(sid string) Session
	// DeleteSession 根据session id删除session
	DeleteSession(sid string)
}

SessionManager session管理器,对session进行生成、获取、删除操作。

var GlobalSessionManager SessionManager // 全局session管理器

type UrlPattern

type UrlPattern struct {
	UrlPatterns []Pattern
	// contains filtered or unexported fields
}

UrlPattern 是URL路由,此处存储URL映射。

func (*UrlPattern) AppendRouterPattern

func (urlPattern *UrlPattern) AppendRouterPattern(pattern Pattern, v interface {
	Handle(http.ResponseWriter, *http.Request)
})

AppendRouterPattern 向http服务挂载单个Router,Router中配置有url对应的handler以及对应的中间件

func (*UrlPattern) Init

func (urlPattern *UrlPattern) Init()

Init 初始化url映射,遍历UrlMapping,将handler与对应的URL依次挂载到http服务上

type UrlPatternHandle

type UrlPatternHandle struct {
	Handler interface{}
	// contains filtered or unexported fields
}

UrlPatternHandle 是URL路由句柄,用来驱动url路由以及其映射的handler

func (UrlPatternHandle) Handle

func (urlPatternMidWare UrlPatternHandle) Handle(responseWriter http.ResponseWriter, request *http.Request)

Handle 封装HTTP请求的中间件,主要有以下功能:

  • 1、根据反射找到挂载的handler;
  • 2、调用handler的InitHandler方法;
  • 3、进行HTTP请求预处理,包括判断请求方式是否合法等;
  • 4、调用handler中的功能方法;
  • 5、进行HTTP请求结束处理。

Jump to

Keyboard shortcuts

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