Documentation ¶
Index ¶
- Constants
- Variables
- func GetLittleFileSize() int64
- func GetMaxRequestBodySize() int64
- func SetLittleFileSize(size int64)
- func SetMaxRequestBodySize(size int64)
- type Accounts
- 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) GetGowayServer() (env, appId, appVer, instanceId string)
- func (own *Context) GetGowayTracer() (tid, sid string)
- func (own *Context) GetJsonBody(model any) error
- func (own *Context) GetRequest() *http.Request
- func (own *Context) GetResponse() http.ResponseWriter
- func (own *Context) GetStringBody() (string, error)
- func (own *Context) GetUrlParam(key string) string
- func (own *Context) RequestByGoway(method, url string, headers map[string]string, optGoway OptionGoway, ...) (*http.Response, error)
- func (own *Context) ResponseBytes(code int, data []byte)
- func (own *Context) ResponseError(code int, error string)
- func (own *Context) ResponseError400(error any)
- func (own *Context) ResponseError401()
- func (own *Context) ResponseError404()
- func (own *Context) ResponseError500(error any)
- func (own *Context) ResponseFile(code int, filepath, filename string)
- func (own *Context) ResponseHtml(code int, filename string, data any)
- func (own *Context) ResponseHtmlString(code int, text string, data any)
- func (own *Context) ResponseJson(code int, data any)
- func (own *Context) ResponseString(code int, data string)
- func (own *Context) RunNext()
- func (own *Context) SetHeader(key string, value string)
- func (own *Context) SetHeaders(headers map[string]string)
- func (own *Context) SetStatusCode(code int)
- type Engine
- func (own Engine) AddMiddlewares(middlewares ...Handler)
- func (own Engine) CONNECT(route string, handler Handler)
- func (own Engine) DELETE(route string, handler Handler)
- func (own Engine) GET(route string, handler Handler)
- func (own Engine) HEAD(route string, handler Handler)
- func (own *Engine) ListenAndServe()
- func (own *Engine) ListenAndServeTLS(cert, key string)
- func (engine *Engine) LoadHTMLTemplates(path string)
- func (own Engine) NewGroup(prefix string) *group
- func (own Engine) OPTIONS(route string, handler Handler)
- func (own Engine) PATCH(route string, handler Handler)
- func (own Engine) POST(route string, handler Handler)
- func (own Engine) PUT(route string, handler Handler)
- func (own *Engine) ServeHTTP(resp http.ResponseWriter, req *http.Request)
- func (engine *Engine) SetHTMLFuncs(funcs template.FuncMap)
- func (own Engine) SetStatic(route string, root string)
- func (own Engine) TRACE(route string, handler Handler)
- type Handler
- type Json
- type OptionGoway
Constants ¶
const DynamicRouteKey = ":*"
动态路由的节点的key
const Version = "0.0.1.0"
Variables ¶
var ( GowayTracer = http.CanonicalHeaderKey("Goway-Tracer") GowayServer = http.CanonicalHeaderKey("Goway-Server") )
Functions ¶
func GetLittleFileSize ¶
func GetLittleFileSize() int64
func GetMaxRequestBodySize ¶
func GetMaxRequestBodySize() int64
func SetLittleFileSize ¶
func SetLittleFileSize(size int64)
func SetMaxRequestBodySize ¶
func SetMaxRequestBodySize(size int64)
Types ¶
type Context ¶
type Context struct { // 请求信息 Path string // 请求路由 Method string // 请求方法 Headers http.Header // 请求头 Params map[string]string // 路由参数 // 响应信息 StatusCode int // 响应状态码 // contains filtered or unexported fields }
Context 定义请求响应上下文
func (*Context) GetBasicAuth ¶
GetBasicAuth 获取基本认证的账号密码
func (*Context) GetBytesBody ¶
GetBytesBody 获取bytes格式请求体
func (*Context) GetFormValue ¶
GetFormParam 获取表单参数
func (*Context) GetGowayServer ¶
GetGowayServer 尝试获取 Goway 网关的代理数据:env, app id, app ver, instance id
func (*Context) GetGowayTracer ¶
GetGowayTracer 尝试获取 Goway 网关中的的链路 ID:trace id 和 span id
func (*Context) GetJsonBody ¶
GetJsonBody 获取json格式请求体
func (*Context) GetRequest ¶
func (*Context) GetResponse ¶
func (own *Context) GetResponse() http.ResponseWriter
func (*Context) GetStringBody ¶
GetJsonBody 获取string格式请求体
func (*Context) GetUrlParam ¶
GetUrlParam 获取动态路由参数
func (*Context) RequestByGoway ¶
func (own *Context) RequestByGoway(method, url string, headers map[string]string, optGoway OptionGoway, body io.Reader) (*http.Response, error)
RequestByGoway 尝试通过 Goway 网关发起请求
func (*Context) ResponseBytes ¶
ResponseBytes 响应字节数组
func (*Context) ResponseError ¶
ResponseFail 响应错误信息
func (*Context) ResponseError400 ¶
ResponseError401 响应400
func (*Context) ResponseError500 ¶
ResponseError500 响应500
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) SetHeaders ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine 定义 HTTP/HTTPS 服务引擎的结构
func NewDefaultEngine ¶
NewDefaultEngine 创建一个默认 HTTP/HTTPS 服务引擎,自带异常恢复和日志记录
func (Engine) AddMiddlewares ¶
func (own Engine) AddMiddlewares(middlewares ...Handler)
AddMiddlewares 添加中间件到当前路由组
func (*Engine) ListenAndServeTLS ¶
ListenAndServe 运行 HTTPS 服务器引擎
func (*Engine) LoadHTMLTemplates ¶
func (*Engine) ServeHTTP ¶
func (own *Engine) ServeHTTP(resp http.ResponseWriter, req *http.Request)
ServeHTTP 实现 http.Hanlder 接口,处理所有的路由请求