Documentation ¶
Index ¶
- Constants
- func InjectionSession(session ISession)
- func Run()
- func SetDefaultApplicationBuilderConfig(config *Config)
- func UseMiddleware(middleware ...IMiddleware)
- func UseMiddlewareFunc(middlewareFunc ...func(ctx *HttpContext, next Next) *HttpContext)
- type ApplicationBuilder
- type Config
- type HttpContext
- type HttpMethod
- type IMiddleware
- type IResponse
- type ISession
- type Listen
- type Next
- type Request
- type Response
- func (r *Response) ClearWriteCache()
- func (r *Response) Error() interface{}
- func (r *Response) GetIsWriteInCache() bool
- func (r *Response) GetMaxResponseCacheLen() int
- func (r *Response) GetMsgData() map[string]interface{}
- func (r *Response) GetSession(key string) (interface{}, error)
- func (r *Response) GetStarted() bool
- func (r *Response) GetWriteCache() []byte
- func (r *Response) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (r *Response) ReadStatusCode() int
- func (r *Response) Redirect(redirectPath string)
- func (r *Response) RemoveCookie(ck *http.Cookie)
- func (r *Response) RemoveCookieByName(name string)
- func (r *Response) RemoveSession()
- func (r *Response) SetCookie(c *http.Cookie)
- func (r *Response) SetCookieUseKeyValue(key string, val string)
- func (r *Response) SetError(err interface{})
- func (r *Response) SetIsWriteInCache(b bool)
- func (r *Response) SetMaxResponseCacheLen(b int)
- func (r *Response) SetMsgData(data map[string]interface{})
- func (r *Response) SetSession(key string, val interface{}) error
- func (r *Response) SetStack(str string)
- func (r *Response) Stack() string
- func (r *Response) UpdateSession() error
- func (r *Response) WebSocket(upgrades ...*websocket.Upgrader) (conn *websocket.Conn, err error)
- func (r *Response) Write(b []byte) (int, error)
- func (r *Response) WriteHeader(statusCode int)
- func (r *Response) WriteJson(i interface{}) error
- type Session
- type SessionMgr
- func (mgr *SessionMgr) GC()
- func (mgr *SessionMgr) GetLastAccessTime(sessionID string) time.Time
- func (mgr *SessionMgr) GetSession(sessionID string) (map[interface{}]interface{}, error)
- func (mgr *SessionMgr) GetSessionIDList() []string
- func (mgr *SessionMgr) GetSessionKeyValue() (string, error)
- func (mgr *SessionMgr) Init(SessionAliveTime time.Duration) error
- func (mgr *SessionMgr) NewSessionID() string
- func (mgr *SessionMgr) RemoveBySessionID(sessionID string) error
- func (mgr *SessionMgr) SetSession(sessionID string, m map[interface{}]interface{}) error
Constants ¶
View Source
const (
VERSION = "1.00"
)
Variables ¶
This section is empty.
Functions ¶
func InjectionSession ¶
func InjectionSession(session ISession)
InjectionSession 向默认管道注入session去数据的接口
func SetDefaultApplicationBuilderConfig ¶
func SetDefaultApplicationBuilderConfig(config *Config)
func UseMiddlewareFunc ¶
func UseMiddlewareFunc(middlewareFunc ...func(ctx *HttpContext, next Next) *HttpContext)
UseMiddlewareFunc 中间件func注册接口
Types ¶
type ApplicationBuilder ¶
type ApplicationBuilder struct { Config *Config // contains filtered or unexported fields }
ApplicationBuilder ApplicationBuilder管道构造器
func GetDefaultApplicationBuilder ¶
func GetDefaultApplicationBuilder() *ApplicationBuilder
func NewFreeFishApplicationBuilder ¶
func NewFreeFishApplicationBuilder() *ApplicationBuilder
NewFreeFishApplicationBuilder 创建一个ApplicationBuilder管道
func (*ApplicationBuilder) InjectionSession ¶
func (app *ApplicationBuilder) InjectionSession(session ISession)
InjectionSession 向管道注入session去数据的接口
func (*ApplicationBuilder) UseMiddleware ¶
func (app *ApplicationBuilder) UseMiddleware(middleware ...IMiddleware)
UseMiddleware 中间件注册接口
func (*ApplicationBuilder) UseMiddlewareFunc ¶
func (app *ApplicationBuilder) UseMiddlewareFunc(middlewareFunc ...func(ctx *HttpContext, next Next) *HttpContext)
UseMiddlewareFunc 中间件func注册接口
type Config ¶
type Config struct { AppName string RunMode string ServerName string // EnableGzip 是否开启Gzip压缩 EnableGzip bool // EnableSession 是否启用Session EnableSession bool // SessionAliveTime Session的存在时间 SessionAliveTime time.Duration // MaxResponseCacheLen 响应数据最大缓存长度 MaxResponseCacheLen int // SessionCookieName Session的客户端Cookie名字 SessionCookieName string // RecoverPanic 是否在管道最末端捕获Panic,以取代框架的处理Panic函数 RecoverPanic bool // RecoverFunc 捕获Panic的处理函数 RecoverFunc func(ctx *HttpContext) Listen Listen }
type HttpContext ¶
type HttpMethod ¶
type HttpMethod string
const ( MethodGet HttpMethod = "GET" MethodHead HttpMethod = "HEAD" MethodPost HttpMethod = "POST" MethodPut HttpMethod = "PUT" MethodPatch HttpMethod = "PATCH" // RFC 5789 MethodDelete HttpMethod = "DELETE" MethodConnect HttpMethod = "CONNECT" MethodOptions HttpMethod = "OPTIONS" MethodTrace HttpMethod = "TRACE" )
type IMiddleware ¶
type IMiddleware interface { // Middleware 中间件的逻辑处理函数 框架会调用 Middleware(ctx *HttpContext, next Next) *HttpContext // LastInit 注册框架后 框架会自动调用这个函数 LastInit(*Config) }
IMiddleware 中间件类型接口
type IResponse ¶
type IResponse interface { // WebSocket 升级为WebSocket服务 upgrades为空时采用默认的参数 为多个时只采用第一个作为WebSocket参数 WebSocket(upgrades ...*websocket.Upgrader) (conn *websocket.Conn, err error) Hijack() (net.Conn, *bufio.ReadWriter, error) // RemoveSession 移除Session RemoveSession() // GetSession 获取指定key的session值 GetSession(key string) (interface{}, error) // UpdateSession 更新session值 UpdateSession() error // SetSession 设置session值 SetSession(key string, val interface{}) error // SetCookie 设置Cookie SetCookie(c *http.Cookie) // SetCookieUseKeyValue 设置Cookie SetCookieUseKeyValue(key string, val string) // RemoveCookieByName 通过cookie名字移除Cookie RemoveCookieByName(name string) // WriteHeader 设置响应状态值 WriteHeader(statusCode int) // ReadStatusCode 读取响应状态值 ReadStatusCode() int // RemoveCookie 通过cookie移除Cookie RemoveCookie(ck *http.Cookie) // Write 写入前端的数据 Write(b []byte) (int, error) // GetWriteCache 获取写入前端的缓存 GetWriteCache() []byte // ClearWriteCache 清除写入前端的缓存 ClearWriteCache() // WriteJson 写入前端的json数据 WriteJson(i interface{}) error // Redirect 重定向路径 Redirect(redirectPath string) // GetStarted 是否已经向前端写入数据了,默认是开启的,且GetMaxResponseCacheLen()设置很小 GetStarted() bool // GetIsWriteInCache 获取当前请求是否临时缓存数据进入缓存中 GetIsWriteInCache() bool // SetIsWriteInCache 设置是否延迟把写入前端的数据写入前端,即使设置了延迟写入前端, // 但当数据长度超过了配置文件设置的 MaxResponseCacheLen是依然会写入前端, // 判断是否已经写入前端 调用 GetStarted()进行判断 SetIsWriteInCache(bool) Header() http.Header // GetMaxResponseCacheLen 查看延迟写入前端的数据的最大值 GetMaxResponseCacheLen() int // SetMaxResponseCacheLen 设置延迟写入前端的数据的最大值,GetIsWriteInCache()为True时生效 SetMaxResponseCacheLen(int) // GetMsgData 获取传送数据 GetMsgData() map[string]interface{} // SetMsgData 设置传送数据 SetMsgData(map[string]interface{}) // Stack 500 错误的堆栈信息,其他状态为空 Stack() string // Error 500 错误的信息,其他状态为空 Error() interface{} SetStack(string) SetError(interface{}) // contains filtered or unexported methods }
type ISession ¶
type ISession interface { // Init 初始化接口 Init(SessionAliveTime time.Duration) error // GetSession 获取指定sessionID的值 GetSession(sessionID string) (map[interface{}]interface{}, error) // GetSessionKeyValue 创建一个sessionID GetSessionKeyValue() (string, error) // SetSession 设置sessionID的值 SetSession(sessionID string, m map[interface{}]interface{}) error // RemoveBySessionID 移除sessionID及其值 RemoveBySessionID(sessionID string) error }
ISession Session接口
type Listen ¶
type Listen struct { // ServerTimeOut 服务超时时间 ServerTimeOut time.Duration // WriteTimeout 写超时时间 WriteTimeout time.Duration MaxHeaderBytes int // EnableHTTP 是否开启http服务 EnableHTTP bool // HTTPAddr http服务运行ip地址 HTTPAddr string // HTTPPort http服务运行端口 HTTPPort int // EnableHTTPS 是否开启Https服务 EnableHTTPS bool // HTTPSAddr https服务运行ip地址 HTTPSAddr string // HTTPSPort https服务运行端口 HTTPSPort int // HTTPSCertFile httpsCertFile文件地址 HTTPSCertFile string // HTTPSKeyFile HTTPSKeyFile文件地址 HTTPSKeyFile string }
type Response ¶
type Response struct { http.ResponseWriter // 是否调用过Write Started bool Gzip *gzip.Writer IsOpenGzip bool SessionId string SessionCookieName string SessionAliveTime time.Duration // contains filtered or unexported fields }
func (*Response) GetIsWriteInCache ¶
func (*Response) GetMaxResponseCacheLen ¶
func (*Response) GetMsgData ¶
GetMsgData 获取传递的信息
func (*Response) GetSession ¶
func (*Response) GetStarted ¶
func (*Response) ReadStatusCode ¶
func (*Response) RemoveCookie ¶
RemoveCookie 通过cookie移除Cookie
func (*Response) RemoveCookieByName ¶
RemoveCookieByName 通过cookie名字移除Cookie
func (*Response) RemoveSession ¶
func (r *Response) RemoveSession()
func (*Response) SetCookieUseKeyValue ¶
SetCookieUseKeyValue 设置Cookie
func (*Response) SetIsWriteInCache ¶
func (*Response) SetMaxResponseCacheLen ¶
func (*Response) SetMsgData ¶
SetMsgData 设置传递的信心
func (*Response) SetSession ¶
func (*Response) UpdateSession ¶
func (*Response) WriteHeader ¶
type SessionMgr ¶
type SessionMgr struct {
// contains filtered or unexported fields
}
SessionMgr Session会话管理
func NewSessionMgr ¶
func NewSessionMgr(maxLifeTime time.Duration) *SessionMgr
NewSessionMgr 创建会话管理器(cookieName:在浏览器中cookie的名字;maxLifeTime:最长生命周期)
func (*SessionMgr) GetLastAccessTime ¶
func (mgr *SessionMgr) GetLastAccessTime(sessionID string) time.Time
GetLastAccessTime 更新最后访问时间
func (*SessionMgr) GetSession ¶
func (mgr *SessionMgr) GetSession(sessionID string) (map[interface{}]interface{}, error)
GetSession 得到session里面的值
func (*SessionMgr) GetSessionIDList ¶
func (mgr *SessionMgr) GetSessionIDList() []string
GetSessionIDList 得到sessionID列表
func (*SessionMgr) GetSessionKeyValue ¶
func (mgr *SessionMgr) GetSessionKeyValue() (string, error)
func (*SessionMgr) RemoveBySessionID ¶
func (mgr *SessionMgr) RemoveBySessionID(sessionID string) error
func (*SessionMgr) SetSession ¶
func (mgr *SessionMgr) SetSession(sessionID string, m map[interface{}]interface{}) error
SetSession 设置session里面的值
Source Files ¶
Click to show internal directories.
Click to hide internal directories.