add more inernal logging points for core components

This commit is contained in:
John
2020-02-24 21:09:19 +08:00
parent c70bc7c96a
commit 42fd583bfd
21 changed files with 83 additions and 44 deletions

View File

@ -11,17 +11,17 @@ import (
"github.com/gogf/gf/net/ghttp"
)
// 控制器基类
// Controller is used for controller register of ghttp.Server.
type Controller struct {
Request *ghttp.Request // 请求数据对象
Response *ghttp.Response // 返回数据对象(r.Response)
Server *ghttp.Server // Web Server对象(r.Server)
Cookie *ghttp.Cookie // COOKIE操作对象(r.Cookie)
Session *ghttp.Session // SESSION操作对象
View *View // 视图对象
Request *ghttp.Request
Response *ghttp.Response
Server *ghttp.Server
Cookie *ghttp.Cookie
Session *ghttp.Session
View *View
}
// 控制器初始化接口方法
// Init is the callback function for each request initialization.
func (c *Controller) Init(r *ghttp.Request) {
c.Request = r
c.Response = r.Response
@ -31,12 +31,12 @@ func (c *Controller) Init(r *ghttp.Request) {
c.Session = r.Session
}
// 控制器结束请求接口方法
// Shut is the callback function for each request close.
func (c *Controller) Shut() {
}
// 退出请求执行
// Exit equals to function Request.Exit().
func (c *Controller) Exit() {
c.Request.Exit()
}

View File

@ -7,5 +7,4 @@
package gmvc
// Model is the base struct for model.
type Model struct {
}
type Model struct{}

View File

@ -16,15 +16,17 @@ import (
"github.com/gogf/gf/os/gview"
)
// 基于控制器注册的MVC视图基类(一个请求一个视图对象,用完即销毁)
// View is the view object for controller.
// It's initialized when controller request initializes and destroyed
// when the controller request closes.
type View struct {
mu sync.RWMutex // 并发互斥锁
view *gview.View // 底层视图对象
data gview.Params // 视图数据/模板变量
response *ghttp.Response // 数据返回对象
mu sync.RWMutex
view *gview.View
data gview.Params
response *ghttp.Response
}
// 创建一个MVC请求中使用的视图对象
// NewView creates and returns a controller view object.
func NewView(w *ghttp.Response) *View {
return &View{
view: gins.View(),
@ -33,7 +35,7 @@ func NewView(w *ghttp.Response) *View {
}
}
// 批量绑定模板变量,即调用之后每个线程都会生效,因此有并发安全控制
// Assigns assigns template variables to this view object.
func (view *View) Assigns(data gview.Params) {
view.mu.Lock()
for k, v := range data {
@ -42,14 +44,15 @@ func (view *View) Assigns(data gview.Params) {
view.mu.Unlock()
}
// 绑定模板变量,即调用之后每个线程都会生效,因此有并发安全控制
// Assign assigns one template variable to this view object.
func (view *View) Assign(key string, value interface{}) {
view.mu.Lock()
view.data[key] = value
view.mu.Unlock()
}
// 解析模板,并返回解析后的内容
// Parse parses given template file <tpl> with assigned template variables
// and returns the parsed template content.
func (view *View) Parse(file string) (string, error) {
view.mu.RLock()
defer view.mu.RUnlock()
@ -57,7 +60,8 @@ func (view *View) Parse(file string) (string, error) {
return buffer, err
}
// 直接解析模板内容,并返回解析后的内容
// ParseContent parses given template file <file> with assigned template variables
// and returns the parsed template content.
func (view *View) ParseContent(content string) (string, error) {
view.mu.RLock()
defer view.mu.RUnlock()
@ -65,14 +69,14 @@ func (view *View) ParseContent(content string) (string, error) {
return buffer, err
}
// 使用自定义方法对模板变量执行加锁修改操作
// LockFunc locks writing for template variables by callback function <f>.
func (view *View) LockFunc(f func(data gview.Params)) {
view.mu.Lock()
defer view.mu.Unlock()
f(view.data)
}
// 使用自定义方法对模板变量执行加锁读取操作
// LockFunc locks reading for template variables by callback function <f>.
func (view *View) RLockFunc(f func(data gview.Params)) {
view.mu.RLock()
defer view.mu.RUnlock()
@ -93,7 +97,7 @@ func (view *View) BindFuncMap(funcMap gview.FuncMap) {
view.view.BindFuncMap(funcMap)
}
// 解析并显示指定模板
// Display parses and writes the parsed template file content to http response.
func (view *View) Display(file ...string) error {
name := "index.tpl"
if len(file) > 0 {
@ -110,7 +114,7 @@ func (view *View) Display(file ...string) error {
return nil
}
// 解析并显示模板内容
// DisplayContent parses and writes the parsed content to http response.
func (view *View) DisplayContent(content string) error {
if content, err := view.ParseContent(content); err != nil {
if !gmode.IsProduct() {