Documentation ¶
Overview ¶
Copyright [2018] [jc3wish]
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright [2018] [jc3wish]
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright [2018] [jc3wish]
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright [2018] [jc3wish]
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright [2018] [jc3wish]
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Variables
- func AddStaticRoute(route string, dir string)
- func NewRouteController(controllerType reflect.Type, controllerName string, funName string, ...) *routeController
- func Router(route string, c ControllerInterface, FunNames string) error
- func Start(IpAndPort string) error
- func StartSession(cookieName ...string)
- func StartTLS(IpAndPort string, serverKey string, serverCrt string) error
- type Context
- func (ctx *Context) Get(key string, defaultVal ...string) string
- func (ctx *Context) GetParamBool(key string, defaultVal ...bool) bool
- func (ctx *Context) GetParamInt64(key string, defaultVal ...int64) (int64, error)
- func (ctx *Context) GetParamUInt64(key string, defaultVal ...uint64) (uint64, error)
- type Controller
- func (c *Controller) AddTemplate(tpl ...string)
- func (c *Controller) Finish()
- func (c *Controller) Init(ctx *Context, controllerName, actionName string)
- func (c *Controller) IsHtmlOutput() bool
- func (c *Controller) NormalStop()
- func (c *Controller) Prepare()
- func (c *Controller) SetData(key string, data interface{})
- func (c *Controller) SetJsonData(data interface{})
- func (c *Controller) SetOutputByUser()
- func (c *Controller) SetTemplate(t *template.Template, err error)
- func (c *Controller) StopRun()
- func (c *Controller) StopServeJSON()
- func (c *Controller) StopServeJSONP(jsonp ...string)
- type ControllerInterface
- type OutputFormat
- type Session
- type SessionMgr
- func (mgr *SessionMgr) CheckCookieValid(w http.ResponseWriter, r *http.Request) string
- func (mgr *SessionMgr) EndSession(w http.ResponseWriter, r *http.Request)
- func (mgr *SessionMgr) EndSessionBy(sessionID string)
- func (mgr *SessionMgr) GC()
- func (mgr *SessionMgr) GetLastAccessTime(sessionID string) time.Time
- func (mgr *SessionMgr) GetSessionIDList() []string
- func (mgr *SessionMgr) GetSessionVal(sessionID string, key interface{}) (interface{}, bool)
- func (mgr *SessionMgr) NewSessionID() string
- func (mgr *SessionMgr) SetSessionVal(sessionID string, key interface{}, value interface{})
- func (mgr *SessionMgr) StartSession(w http.ResponseWriter, r *http.Request) string
Constants ¶
This section is empty.
Variables ¶
var (
ErrAbort = errors.New("user stop run")
)
Functions ¶
func AddStaticRoute ¶
func NewRouteController ¶
func StartSession ¶
func StartSession(cookieName ...string)
Types ¶
type Context ¶
type Context struct { Request *http.Request ResponseWriter http.ResponseWriter Session *SessionMgr }
func (*Context) GetParamBool ¶
func (*Context) GetParamInt64 ¶
type Controller ¶
type Controller struct { Ctx *Context ControllerName string ActionName string Data map[string]interface{} Format OutputFormat Template *template.Template // contains filtered or unexported fields }
func (*Controller) AddTemplate ¶
func (c *Controller) AddTemplate(tpl ...string)
func (*Controller) Finish ¶
func (c *Controller) Finish()
func (*Controller) Init ¶
func (c *Controller) Init(ctx *Context, controllerName, actionName string)
func (*Controller) IsHtmlOutput ¶
func (c *Controller) IsHtmlOutput() bool
func (*Controller) NormalStop ¶
func (c *Controller) NormalStop()
func (*Controller) Prepare ¶
func (c *Controller) Prepare()
func (*Controller) SetData ¶
func (c *Controller) SetData(key string, data interface{})
func (*Controller) SetJsonData ¶
func (c *Controller) SetJsonData(data interface{})
func (*Controller) SetOutputByUser ¶
func (c *Controller) SetOutputByUser()
func (*Controller) SetTemplate ¶
func (c *Controller) SetTemplate(t *template.Template, err error)
func (*Controller) StopRun ¶
func (c *Controller) StopRun()
func (*Controller) StopServeJSON ¶
func (c *Controller) StopServeJSON()
func (*Controller) StopServeJSONP ¶
func (c *Controller) StopServeJSONP(jsonp ...string)
type ControllerInterface ¶
type ControllerInterface interface { Init(ct *Context, controllerName, actionName string) Prepare() Finish() StopServeJSON() StopServeJSONP(jsonp ...string) StopRun() NormalStop() IsHtmlOutput() bool SetOutputByUser() AddTemplate(tpl ...string) SetTemplate(t *template.Template, err error) }
ControllerInterface is an interface to uniform all controller handler.
type OutputFormat ¶
type OutputFormat int8
const ( JSON_TYPE OutputFormat = 1 JSONP_TYPE OutputFormat = 2 HTML_TYPE OutputFormat = 0 OTHER_TYPE OutputFormat = -1 )
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
—————————————————————————— 会话
type SessionMgr ¶
type SessionMgr struct {
// contains filtered or unexported fields
}
Session会话管理
func NewSessionMgr ¶
func NewSessionMgr(cookieName string, maxLifeTime int64) *SessionMgr
创建会话管理器(cookieName:在浏览器中cookie的名字;maxLifeTime:最长生命周期)
func (*SessionMgr) CheckCookieValid ¶
func (mgr *SessionMgr) CheckCookieValid(w http.ResponseWriter, r *http.Request) string
判断Cookie的合法性(每进入一个页面都需要判断合法性)
func (*SessionMgr) EndSession ¶
func (mgr *SessionMgr) EndSession(w http.ResponseWriter, r *http.Request)
结束Session
func (*SessionMgr) GetLastAccessTime ¶
func (mgr *SessionMgr) GetLastAccessTime(sessionID string) time.Time
更新最后访问时间
func (*SessionMgr) GetSessionIDList ¶
func (mgr *SessionMgr) GetSessionIDList() []string
得到sessionID列表
func (*SessionMgr) GetSessionVal ¶
func (mgr *SessionMgr) GetSessionVal(sessionID string, key interface{}) (interface{}, bool)
得到session里面的值
func (*SessionMgr) SetSessionVal ¶
func (mgr *SessionMgr) SetSessionVal(sessionID string, key interface{}, value interface{})
设置session里面的值
func (*SessionMgr) StartSession ¶
func (mgr *SessionMgr) StartSession(w http.ResponseWriter, r *http.Request) string
在开始页面登陆页面,开始Session