Documentation ¶
Index ¶
- Constants
- func SetLittleFileSize(size int64)
- func SetMaxRequestBodySize(size int64)
- type Context
- func (own *Context) GetBasicAuth() (username, password string)
- func (own *Context) GetBytesBody() ([]byte, error)
- func (own *Context) GetFormValue(key string) string
- func (own *Context) GetJsonBody(model any) error
- func (own *Context) GetStringBody() (string, error)
- func (own *Context) Query(key string) string
- func (own *Context) QueryMore(keys ...string) map[string]string
- func (own *Context) ResponseBytes(code int, data []byte) error
- func (own *Context) ResponseErrorBytes(code int, err []byte) error
- func (own *Context) ResponseErrorJson(code int, err any) error
- func (own *Context) ResponseErrorString(code int, err string)
- func (own *Context) ResponseFile(code int, filepath, filename string) error
- func (own *Context) ResponseHtml(code int, filename string, data any) error
- func (own *Context) ResponseHtmlString(code int, text string, data any) error
- func (own *Context) ResponseJson(code int, data any) error
- func (own *Context) ResponseString(code int, data string) error
- func (own *Context) RunNext()
- func (own *Context) SetRequestHeaders(headers map[string]string)
- func (own *Context) SetResponseHeaders(headers map[string]string)
- func (own *Context) SetStatusCode(code int)
- type HandleFunc
- type Hookor
- type HttpServer
- func (own *HttpServer) DisableGeneralOptionsHandler() *HttpServer
- func (own *HttpServer) ListenAndServe()
- func (own *HttpServer) ListenAndServeTLS(cert, perm string)
- func (own *HttpServer) LoadHTMLTemplates(path string)
- func (own *HttpServer) ServeHTTP(resp http.ResponseWriter, req *http.Request)
- func (own *HttpServer) SetHTMLFuncs(funcs template.FuncMap)
- func (own *HttpServer) WithBaseContextFunc(handleFunc func(net.Listener) context.Context) *HttpServer
- func (own *HttpServer) WithConnContextFunc(handleFunc func(ctx context.Context, c net.Conn) context.Context) *HttpServer
- func (own *HttpServer) WithConnStateFunc(handleFunc func(net.Conn, http.ConnState)) *HttpServer
- func (own *HttpServer) WithIdleTimeout(timeout time.Duration) *HttpServer
- func (own *HttpServer) WithMaxHeaderBytes(size int) *HttpServer
- func (own *HttpServer) WithReadHeaderTimeout(timeout time.Duration) *HttpServer
- func (own *HttpServer) WithReadTimeout(timeout time.Duration) *HttpServer
- func (own *HttpServer) WithTLSConfig(tls *tls.Config) *HttpServer
- func (own *HttpServer) WithTLSNextProto(TLSUpgrade map[string]func(*http.Server, *tls.Conn, http.Handler)) *HttpServer
- func (own *HttpServer) WithWriteTimeout(timeout time.Duration) *HttpServer
- type Json
- type RouteGroup
- func (own *RouteGroup) AddMiddlewares(middlewares ...HandleFunc)
- func (own *RouteGroup) DELETE(part string, handler HandleFunc)
- func (own *RouteGroup) GET(part string, handler HandleFunc)
- func (own *RouteGroup) NewGroup(prefix string) *RouteGroup
- func (own *RouteGroup) OPTIONS(part string, handler HandleFunc)
- func (own *RouteGroup) POST(part string, handler HandleFunc)
- func (own *RouteGroup) PUT(part string, handler HandleFunc)
- func (own *RouteGroup) SetStatic(part string, root string)
Constants ¶
const ( ERR_NOT_FOUND = "404 Not Found" ERR_SERVICE_UNREACHED = "503 Service Unreached" ERR_METHOD_NOT_ALLOWED = "405 Method Not Allowed" ERR_INTERNAL_SERVER_ERROR = "500 Internal Server Error" )
Variables ¶
This section is empty.
Functions ¶
func SetLittleFileSize ¶
func SetLittleFileSize(size int64)
func SetMaxRequestBodySize ¶
func SetMaxRequestBodySize(size int64)
Types ¶
type Context ¶
type Context struct { // 响应状态码 StatusCode int // 请求路由 Path string // 请求方法 Method string // 查询参数 QueryParams url.Values // 原始请求 Request *http.Request // 原始响应 Response http.ResponseWriter // contains filtered or unexported fields }
Context 定义请求响应上下文的数据结构
func (*Context) GetBasicAuth ¶
GetBasicAuth 获取基本认证的账号密码
func (*Context) GetBytesBody ¶
GetBytesBody 获取bytes格式请求体
func (*Context) GetFormValue ¶
GetFormParam 获取表单参数
func (*Context) GetJsonBody ¶
GetJsonBody 获取json格式请求体
func (*Context) GetStringBody ¶
GetJsonBody 获取string格式请求体
func (*Context) ResponseBytes ¶
ResponseBytes 响应字节数组
func (*Context) ResponseErrorBytes ¶
ResponseErrorBytes 响应Bytes错误信息
func (*Context) ResponseErrorJson ¶
ResponseErrorJson 响应Json错误信息
func (*Context) ResponseErrorString ¶
ResponseErrorString 响应String错误信息
func (*Context) ResponseFile ¶
ResponseFile 响应单个文件
func (*Context) ResponseHtml ¶
ResponseHtml 响应单个HTML文件
func (*Context) ResponseHtmlString ¶
ResponseHtmlString 响应HTML字符串
func (*Context) ResponseJson ¶
ResponseJson 响应Json格式数据
func (*Context) ResponseString ¶
ResponseString 响应字符串
func (*Context) SetRequestHeaders ¶
SetRequestHeaders 设置请求头
func (*Context) SetResponseHeaders ¶
SetResponseHeaders 设置响应头
type HandleFunc ¶
type HandleFunc func(*Context)
HandleFunc 定义请求处理函数的类型
func Receive ¶
func Receive(receiver *receiver.Receiver) HandleFunc
type HttpServer ¶
type HttpServer struct { // 继承路由组,HTTP服务器本身也是个路由组,即根路由组 *RouteGroup // contains filtered or unexported fields }
HttpServer 定义HTTP服务器的数据结构
func NewDefaultServer ¶
func NewDefaultServer(addr string) *HttpServer
NewDefaultEngine 创建一个默认 HTTP/HTTPS 服务引擎,自带异常恢复和日志记录
func (*HttpServer) DisableGeneralOptionsHandler ¶
func (own *HttpServer) DisableGeneralOptionsHandler() *HttpServer
func (*HttpServer) ListenAndServeTLS ¶
func (own *HttpServer) ListenAndServeTLS(cert, perm string)
ListenAndServe 运行HTTPS服务
func (*HttpServer) LoadHTMLTemplates ¶
func (own *HttpServer) LoadHTMLTemplates(path string)
func (*HttpServer) ServeHTTP ¶
func (own *HttpServer) ServeHTTP(resp http.ResponseWriter, req *http.Request)
ServeHTTP:实现http.Hanlder接口,处理所有的路由请求
func (*HttpServer) SetHTMLFuncs ¶
func (own *HttpServer) SetHTMLFuncs(funcs template.FuncMap)
func (*HttpServer) WithBaseContextFunc ¶
func (own *HttpServer) WithBaseContextFunc(handleFunc func(net.Listener) context.Context) *HttpServer
WithBaseContextFunc 指定一个函数,返回服务器上传入请求的基本上下文
func (*HttpServer) WithConnContextFunc ¶
func (own *HttpServer) WithConnContextFunc(handleFunc func(ctx context.Context, c net.Conn) context.Context) *HttpServer
WithConnContextFunc 指定一个函数来修改用于新连接的上下文。所提供的ctx是从基本上下文派生的,并且具有ServerContextKey值
func (*HttpServer) WithConnStateFunc ¶
func (own *HttpServer) WithConnStateFunc(handleFunc func(net.Conn, http.ConnState)) *HttpServer
WithConnStateFunc 指定了一个可选的回调函数,当客户端连接更改状态时调用该函数
func (*HttpServer) WithIdleTimeout ¶
func (own *HttpServer) WithIdleTimeout(timeout time.Duration) *HttpServer
func (*HttpServer) WithMaxHeaderBytes ¶
func (own *HttpServer) WithMaxHeaderBytes(size int) *HttpServer
func (*HttpServer) WithReadHeaderTimeout ¶
func (own *HttpServer) WithReadHeaderTimeout(timeout time.Duration) *HttpServer
func (*HttpServer) WithReadTimeout ¶
func (own *HttpServer) WithReadTimeout(timeout time.Duration) *HttpServer
func (*HttpServer) WithTLSConfig ¶
func (own *HttpServer) WithTLSConfig(tls *tls.Config) *HttpServer
func (*HttpServer) WithTLSNextProto ¶
func (own *HttpServer) WithTLSNextProto(TLSUpgrade map[string]func(*http.Server, *tls.Conn, http.Handler)) *HttpServer
WithTLSNextProto 指定一个函数,以便在发生ALPN协议升级时接管所提供TLS连接的所有权。如果TLSNextProto不是nil,则不会自动启用HTTP/2支持
func (*HttpServer) WithWriteTimeout ¶
func (own *HttpServer) WithWriteTimeout(timeout time.Duration) *HttpServer
type RouteGroup ¶
type RouteGroup struct {
// contains filtered or unexported fields
}
RouteGroup 定义路由组的数据结构
func (*RouteGroup) AddMiddlewares ¶
func (own *RouteGroup) AddMiddlewares(middlewares ...HandleFunc)
AddMiddlewares 添加中间件到当前路由组
func (*RouteGroup) DELETE ¶
func (own *RouteGroup) DELETE(part string, handler HandleFunc)
DELETE 添加DELETE请求路由到当前路由组
func (*RouteGroup) GET ¶
func (own *RouteGroup) GET(part string, handler HandleFunc)
GET 添加GET请求路由到当前路由组
func (*RouteGroup) NewGroup ¶
func (own *RouteGroup) NewGroup(prefix string) *RouteGroup
NewRouteGroup 新建一个路由组
func (*RouteGroup) OPTIONS ¶
func (own *RouteGroup) OPTIONS(part string, handler HandleFunc)
OPTIONS 添加DELETE请求路由到当前路由组
func (*RouteGroup) POST ¶
func (own *RouteGroup) POST(part string, handler HandleFunc)
POST 添加POST请求路由到当前路由组
func (*RouteGroup) PUT ¶
func (own *RouteGroup) PUT(part string, handler HandleFunc)
PUT 添加PUT请求路由到当前路由组
func (*RouteGroup) SetStatic ¶
func (own *RouteGroup) SetStatic(part string, root string)
SetStatic 设置静态文件服务路由