Documentation ¶
Overview ¶
Package smile This software is licensed under the MIT License. You can get more info in license file.
Index ¶
- Constants
- Variables
- func DoCustomInit()
- func GetInitState() bool
- func InitFuncPush(f InitFunc)
- func LogOFF()
- func LogON()
- func Mode() string
- func SetDEBUG()
- func SetDebugger(fnc Debugger)
- func SetInitGoroutine()
- func SetInitSync()
- func SetPRODUCTION()
- func SetRecovery(fnc Recovery)
- func SetTESTING()
- type Context
- func (c *Context) Abort() bool
- func (c *Context) Close()
- func (c *Context) Err() []error
- func (c *Context) GetClientIP() string
- func (c *Context) GetCookie(key string) (*http.Cookie, error)
- func (c *Context) GetFormFile(key string) (multipart.File, *multipart.FileHeader, error)
- func (c *Context) GetHeader() http.Header
- func (c *Context) GetHost() string
- func (c *Context) GetMethod() string
- func (c *Context) GetMultipartFormFile(key string) []*multipart.FileHeader
- func (c *Context) GetMultipartFormParam(key string) []string
- func (c *Context) GetPath() string
- func (c *Context) GetPostParam(key string) string
- func (c *Context) GetProto() string
- func (c *Context) GetQueryParam(key string) string
- func (c *Context) GetQueryString() string
- func (c *Context) GetRawBody() string
- func (c *Context) GetScheme() string
- func (c *Context) GetURL() string
- func (c *Context) GetUserAgent() string
- func (c *Context) Next() error
- func (c *Context) Redirect(url string)
- func (c *Context) SetCookie(cookie *http.Cookie)
- func (c *Context) SetHeader(key, value string)
- type Debugger
- type Engine
- func (e *Engine) GetErrors() []error
- func (e *Engine) GzipOff()
- func (e *Engine) GzipOn()
- func (e *Engine) Run(port string) (err error)
- func (e *Engine) RunTLS(port, cert, key string) (err error)
- func (e *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (e *Engine) SetLoger(l ILogger)
- func (e *Engine) SetRouteGroup(r *RouteGroup)
- type HandlerFunc
- type IEngine
- type ILogger
- type InitFunc
- type Logger
- type Recovery
- type ResponseWriter
- type RouteGroup
- func (rg *RouteGroup) FillRoutes(method string, prefix string, c interface{})
- func (rg *RouteGroup) FormatRoutes() (rsAssign []string, rsAuto []string)
- func (rg *RouteGroup) Get(method string, path string) (HandlerFunc, error)
- func (rg *RouteGroup) PrefixFillRoutes(prefix string, c interface{})
- func (rg *RouteGroup) Set(method string, path string, handler HandlerFunc)
- func (rg *RouteGroup) SetDEL(path string, handler HandlerFunc)
- func (rg *RouteGroup) SetGET(path string, handler HandlerFunc)
- func (rg *RouteGroup) SetMiddleware(fn HandlerFunc)
- func (rg *RouteGroup) SetPOST(path string, handler HandlerFunc)
- func (rg *RouteGroup) SetPUT(path string, handler HandlerFunc)
- func (rg *RouteGroup) SetPathStyleConnector()
- func (rg *RouteGroup) SetPathStyleHump()
- func (rg *RouteGroup) SetRoute404(fn HandlerFunc)
- func (rg *RouteGroup) SetWS(path string, handler HandlerFunc)
Constants ¶
const ( ModeDEBUG = "debug" ModeTESTING = "testing" ModePRO = "production" )
定义了一些模式和HOOK 方便调测
const ( MethodGet = "GET" MethodPost = "POST" MethodWs = "WS" MethodPut = "PUT" MethodDelete = "DELETE" )
定义部分请求类型及其匹配式
const ( StyleHump = "hump" StyleConnect = "connector" )
定义自动生成路由的风格
const (
MaxFileSize = 5 << 20
)
默认文件上传大小限制
Variables ¶
var (
CustomFileSize int64
)
用户自定上传大小限制
var DefaultFile = "index.html"
DefaultFile 文件服务器默认输出文件
Functions ¶
Types ¶
type Context ¶ added in v0.1.2
type Context struct { ResponseWriter Request *http.Request // contains filtered or unexported fields }
Context 一个复合结构,将writer和 request保存到一起,方便被调用 实现了一些便捷方法 从而缩短获取数据的路径长度
func (*Context) GetClientIP ¶ added in v0.1.2
GetClientIP 获取请求的IP地址 从请求头中截取
func (*Context) GetFormFile ¶ added in v0.1.2
GetFormFile 根据键名获取上传文件
func (*Context) GetMultipartFormFile ¶ added in v0.1.2
func (c *Context) GetMultipartFormFile(key string) []*multipart.FileHeader
GetMultipartFormFile 根据键名冲form-data类型中取得上传文件头信息
func (*Context) GetMultipartFormParam ¶ added in v0.1.2
GetMultipartFormParam 根据键名从form-data类型中取值
func (*Context) GetPostParam ¶ added in v0.1.2
GetPostParam 根据键名从post表单中取值
func (*Context) GetQueryParam ¶ added in v0.1.2
GetQueryParam 根据键名从url参数中取值
func (*Context) GetQueryString ¶ added in v0.1.2
GetQueryString 获取请求的url参数
func (*Context) GetRawBody ¶ added in v0.1.2
GetRawBody 获取请求中的body体 当传输类型为 urlencoded时 可用
func (*Context) GetUserAgent ¶ added in v0.1.2
GetUserAgent 获取请求的代理头 user-agent
type Engine ¶
type Engine struct { RouteGroup *RouteGroup Logger ILogger Gzip bool //debug Errors []error // contains filtered or unexported fields }
Engine 一个服务器引擎
type IEngine ¶
type IEngine interface { Init(*Context) IEngine //初始化引擎 Handle() error //执行方法 Check(interface{}) bool //判断是否属于引擎处理请求 GetType() string //获取引擎结构类型 }
IEngine 一个引擎接口
type ResponseWriter ¶
type ResponseWriter interface { http.ResponseWriter http.Hijacker http.Flusher DataSize() int Status() int WriteString(string) (int, error) Done() }
ResponseWriter 定义一个writer接口 该接口可用于http、weibsocket的响应操作
type RouteGroup ¶
type RouteGroup struct { GET map[string]HandlerFunc POST map[string]HandlerFunc WS map[string]HandlerFunc PUT map[string]HandlerFunc DELETE map[string]HandlerFunc // contains filtered or unexported fields }
RouteGroup 路由列表
func (*RouteGroup) FillRoutes ¶
func (rg *RouteGroup) FillRoutes(method string, prefix string, c interface{})
FillRoutes 填充路由基础方法
func (*RouteGroup) FormatRoutes ¶
func (rg *RouteGroup) FormatRoutes() (rsAssign []string, rsAuto []string)
FormatRoutes 返回格式化的路由信息 每个路由信息为一个string
func (*RouteGroup) Get ¶
func (rg *RouteGroup) Get(method string, path string) (HandlerFunc, error)
Get 根据请求方法 获取一个注册的方法
func (*RouteGroup) PrefixFillRoutes ¶
func (rg *RouteGroup) PrefixFillRoutes(prefix string, c interface{})
PrefixFillRoutes 前缀匹配规则 填充路由 暂时只支持GET、POST、WS 将一个Controller结构下的方法按照方法名称注册到routeGroup中
func (*RouteGroup) Set ¶
func (rg *RouteGroup) Set(method string, path string, handler HandlerFunc)
Set 注册一个路由
func (*RouteGroup) SetDEL ¶
func (rg *RouteGroup) SetDEL(path string, handler HandlerFunc)
SetDEL 注册一个PUT方法可用的路由
func (*RouteGroup) SetGET ¶
func (rg *RouteGroup) SetGET(path string, handler HandlerFunc)
SetGET 注册一个GET方法请求到的路由
func (*RouteGroup) SetMiddleware ¶
func (rg *RouteGroup) SetMiddleware(fn HandlerFunc)
SetMiddleware 注册中间件
func (*RouteGroup) SetPOST ¶
func (rg *RouteGroup) SetPOST(path string, handler HandlerFunc)
SetPOST 注册一个POST方法可用的路由
func (*RouteGroup) SetPUT ¶
func (rg *RouteGroup) SetPUT(path string, handler HandlerFunc)
SetPUT 注册一个PUT方法可用的路由
func (*RouteGroup) SetPathStyleConnector ¶
func (rg *RouteGroup) SetPathStyleConnector()
SetPathStyleConnector 设置路径风格为连字符格式 将驼峰转为连接符风格
func (*RouteGroup) SetPathStyleHump ¶
func (rg *RouteGroup) SetPathStyleHump()
SetPathStyleHump 设置路径风格为驼峰 即区分大小写
func (*RouteGroup) SetRoute404 ¶
func (rg *RouteGroup) SetRoute404(fn HandlerFunc)
SetRoute404 注册404回调方法
func (*RouteGroup) SetWS ¶
func (rg *RouteGroup) SetWS(path string, handler HandlerFunc)
SetWS 注册一个websocket路由