diff --git a/.example/other/test.go b/.example/other/test.go index 8bf62b87b..00261b0cf 100644 --- a/.example/other/test.go +++ b/.example/other/test.go @@ -1,13 +1,9 @@ package main import ( - "fmt" - "github.com/gogf/gf/util/grand" + "github.com/gogf/gf/frame/g" ) func main() { - s := "我爱GoFrame" - for i := 0; i <= 10; i++ { - fmt.Println(grand.Str(s, 10)) - } + g.Cfg().Dump() } diff --git a/database/gdb/gdb_mssql.go b/database/gdb/gdb_mssql.go index f838b7902..30abd729f 100644 --- a/database/gdb/gdb_mssql.go +++ b/database/gdb/gdb_mssql.go @@ -14,6 +14,7 @@ package gdb import ( "database/sql" "fmt" + "github.com/gogf/gf/internal/intlog" "github.com/gogf/gf/text/gstr" "strconv" "strings" @@ -35,6 +36,7 @@ func (db *dbMssql) Open(config *ConfigNode) (*sql.DB, error) { config.User, config.Pass, config.Host, config.Port, config.Name, ) } + intlog.Printf("Open: %s", source) if db, err := sql.Open("sqlserver", source); err == nil { return db, nil } else { diff --git a/database/gdb/gdb_mysql.go b/database/gdb/gdb_mysql.go index 9d79b6b45..6cef24755 100644 --- a/database/gdb/gdb_mysql.go +++ b/database/gdb/gdb_mysql.go @@ -9,6 +9,7 @@ package gdb import ( "database/sql" "fmt" + "github.com/gogf/gf/internal/intlog" _ "github.com/gf-third/mysql" ) @@ -28,6 +29,7 @@ func (db *dbMysql) Open(config *ConfigNode) (*sql.DB, error) { config.User, config.Pass, config.Host, config.Port, config.Name, config.Charset, ) } + intlog.Printf("Open: %s", source) if db, err := sql.Open("gf-mysql", source); err == nil { return db, nil } else { diff --git a/database/gdb/gdb_oracle.go b/database/gdb/gdb_oracle.go index 23e79f121..05479292a 100644 --- a/database/gdb/gdb_oracle.go +++ b/database/gdb/gdb_oracle.go @@ -15,6 +15,7 @@ import ( "database/sql" "errors" "fmt" + "github.com/gogf/gf/internal/intlog" "github.com/gogf/gf/text/gstr" "reflect" "strconv" @@ -39,6 +40,7 @@ func (db *dbOracle) Open(config *ConfigNode) (*sql.DB, error) { } else { source = fmt.Sprintf("%s/%s@%s", config.User, config.Pass, config.Name) } + intlog.Printf("Open: %s", source) if db, err := sql.Open("oci8", source); err == nil { return db, nil } else { diff --git a/database/gdb/gdb_pgsql.go b/database/gdb/gdb_pgsql.go index 705edcb9f..04b57727b 100644 --- a/database/gdb/gdb_pgsql.go +++ b/database/gdb/gdb_pgsql.go @@ -14,6 +14,7 @@ package gdb import ( "database/sql" "fmt" + "github.com/gogf/gf/internal/intlog" "github.com/gogf/gf/text/gstr" "strings" @@ -34,6 +35,7 @@ func (db *dbPgsql) Open(config *ConfigNode) (*sql.DB, error) { config.User, config.Pass, config.Host, config.Port, config.Name, ) } + intlog.Printf("Open: %s", source) if db, err := sql.Open("postgres", source); err == nil { return db, nil } else { diff --git a/database/gdb/gdb_sqlite.go b/database/gdb/gdb_sqlite.go index b121953cc..9b44f73f0 100644 --- a/database/gdb/gdb_sqlite.go +++ b/database/gdb/gdb_sqlite.go @@ -12,6 +12,7 @@ package gdb import ( "database/sql" + "github.com/gogf/gf/internal/intlog" "github.com/gogf/gf/text/gstr" ) @@ -26,6 +27,7 @@ func (db *dbSqlite) Open(config *ConfigNode) (*sql.DB, error) { } else { source = config.Name } + intlog.Printf("Open: %s", source) if db, err := sql.Open("sqlite3", source); err == nil { return db, nil } else { diff --git a/database/gredis/gredis_config.go b/database/gredis/gredis_config.go index 65a799ee5..eab96d73d 100644 --- a/database/gredis/gredis_config.go +++ b/database/gredis/gredis_config.go @@ -7,6 +7,7 @@ package gredis import ( + "github.com/gogf/gf/internal/intlog" "time" "github.com/gogf/gf/errors/gerror" @@ -36,6 +37,8 @@ func SetConfig(config Config, name ...string) { } configs.Set(group, config) instances.Remove(group) + + intlog.Printf(`SetConfig for group "%s": %+v`, group, config) } // SetConfigByStr sets the global configuration for specified group with string. @@ -76,6 +79,8 @@ func RemoveConfig(name ...string) { } configs.Remove(group) instances.Remove(group) + + intlog.Printf(`RemoveConfig: %s`, group) } // ConfigFromStr parses and returns config from given str. diff --git a/frame/gmvc/controller.go b/frame/gmvc/controller.go index 48cc47d92..678edb3be 100644 --- a/frame/gmvc/controller.go +++ b/frame/gmvc/controller.go @@ -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() } diff --git a/frame/gmvc/model.go b/frame/gmvc/model.go index afc8a72f5..870ec79da 100644 --- a/frame/gmvc/model.go +++ b/frame/gmvc/model.go @@ -7,5 +7,4 @@ package gmvc // Model is the base struct for model. -type Model struct { -} +type Model struct{} diff --git a/frame/gmvc/view.go b/frame/gmvc/view.go index f28f68fce..b4e35bc71 100644 --- a/frame/gmvc/view.go +++ b/frame/gmvc/view.go @@ -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 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 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 . 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 . 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() { diff --git a/net/ghttp/ghttp_server.go b/net/ghttp/ghttp_server.go index c89f29698..b6126fac6 100644 --- a/net/ghttp/ghttp_server.go +++ b/net/ghttp/ghttp_server.go @@ -11,8 +11,6 @@ import ( "errors" "fmt" "github.com/gogf/gf/debug/gdebug" - "github.com/gogf/gf/internal/intlog" - "github.com/gogf/gf/util/gutil" "net/http" "os" "reflect" @@ -340,10 +338,6 @@ func (s *Server) Start() error { } }) } - if intlog.IsGFDebug() { - intlog.Print("server configuration:") - gutil.Dump(s.config) - } s.dumpRouterMap() return nil } diff --git a/net/ghttp/ghttp_server_config.go b/net/ghttp/ghttp_server_config.go index 54fcbae86..074c57240 100644 --- a/net/ghttp/ghttp_server_config.go +++ b/net/ghttp/ghttp_server_config.go @@ -9,6 +9,7 @@ package ghttp import ( "crypto/tls" "fmt" + "github.com/gogf/gf/internal/intlog" "net/http" "strconv" "time" @@ -151,6 +152,8 @@ func (s *Server) SetConfig(c ServerConfig) error { s.EnableHTTPS(c.HTTPSCertPath, c.HTTPSKeyPath) } SetGraceful(c.Graceful) + + intlog.Printf("SetConfig: %+v", s.config) return nil } diff --git a/os/gbuild/gbuild.go b/os/gbuild/gbuild.go index c0c1f0f81..577e1b739 100644 --- a/os/gbuild/gbuild.go +++ b/os/gbuild/gbuild.go @@ -30,6 +30,9 @@ func init() { } builtInVarMap["gfVersion"] = gf.VERSION builtInVarMap["goVersion"] = runtime.Version() + intlog.Printf("build variables: %+v", builtInVarMap) + } else { + intlog.Print("no build variables") } } diff --git a/os/gcfg/gcfg_config.go b/os/gcfg/gcfg_config.go index b33087ea4..67ef69541 100644 --- a/os/gcfg/gcfg_config.go +++ b/os/gcfg/gcfg_config.go @@ -6,7 +6,10 @@ package gcfg -import "github.com/gogf/gf/container/gmap" +import ( + "github.com/gogf/gf/container/gmap" + "github.com/gogf/gf/internal/intlog" +) var ( // Customized configuration content. @@ -41,9 +44,9 @@ func GetContent(file ...string) string { return configs.Get(name) } -// RemoveConfig removes the global configuration with specified . +// RemoveContent removes the global configuration with specified . // If is not passed, it removes configuration of the default group name. -func RemoveConfig(file ...string) { +func RemoveContent(file ...string) { name := DEFAULT_CONFIG_FILE if len(file) > 0 { name = file[0] @@ -57,6 +60,8 @@ func RemoveConfig(file ...string) { configs.Remove(name) } }) + + intlog.Printf(`RemoveContent: %s`, name) } // ClearContent removes all global configuration contents. @@ -68,4 +73,6 @@ func ClearContent() { v.(*Config).jsons.Clear() } }) + + intlog.Print(`RemoveConfig`) } diff --git a/os/gcfg/gcfg_z_unit_test.go b/os/gcfg/gcfg_z_unit_test.go index 0c2d6c3df..5df2a0066 100644 --- a/os/gcfg/gcfg_z_unit_test.go +++ b/os/gcfg/gcfg_z_unit_test.go @@ -428,7 +428,7 @@ func TestCfg_Config(t *testing.T) { gtest.Assert(gcfg.GetContent("config.yml"), "gf") gcfg.SetContent("gf1", "config.yml") gtest.Assert(gcfg.GetContent("config.yml"), "gf1") - gcfg.RemoveConfig("config.yml") + gcfg.RemoveContent("config.yml") gcfg.ClearContent() gtest.Assert(gcfg.GetContent("name"), "") }) diff --git a/os/gfsnotify/gfsnotify.go b/os/gfsnotify/gfsnotify.go index cd61badb7..fc1f4acb7 100644 --- a/os/gfsnotify/gfsnotify.go +++ b/os/gfsnotify/gfsnotify.go @@ -11,6 +11,7 @@ import ( "errors" "fmt" "github.com/gogf/gf/container/gset" + "github.com/gogf/gf/internal/intlog" "time" "github.com/fsnotify/fsnotify" @@ -94,6 +95,7 @@ func New() (*Watcher, error) { if watcher, err := fsnotify.NewWatcher(); err == nil { w.watcher = watcher } else { + intlog.Printf("New watcher failed: %v", err) return nil, err } w.startWatchLoop() diff --git a/os/gfsnotify/gfsnotify_watcher.go b/os/gfsnotify/gfsnotify_watcher.go index 25009ede1..b9fc4aa66 100644 --- a/os/gfsnotify/gfsnotify_watcher.go +++ b/os/gfsnotify/gfsnotify_watcher.go @@ -43,6 +43,8 @@ func (w *Watcher) AddOnce(name, path string, callbackFunc func(event *Event), re if fileIsDir(subPath) { if err := w.watcher.Add(subPath); err != nil { intlog.Error(err) + } else { + intlog.Printf("watcher adds monitor for: %s", subPath) } } } @@ -85,6 +87,8 @@ func (w *Watcher) addWithCallbackFunc(name, path string, callbackFunc func(event // Add the path to underlying monitor. if err := w.watcher.Add(path); err != nil { intlog.Error(err) + } else { + intlog.Printf("watcher adds monitor for: %s", path) } // Add the callback to global callback map. callbackIdMap.Set(callback.Id, callback) diff --git a/os/gfsnotify/gfsnotify_watcher_loop.go b/os/gfsnotify/gfsnotify_watcher_loop.go index 8d69cf60a..733b55220 100644 --- a/os/gfsnotify/gfsnotify_watcher_loop.go +++ b/os/gfsnotify/gfsnotify_watcher_loop.go @@ -100,6 +100,8 @@ func (w *Watcher) startEventLoop() { // We need no worry about the repeat adding. if err := w.watcher.Add(event.Path); err != nil { intlog.Error(err) + } else { + intlog.Printf("fake remove event, watcher re-adds monitor for: %s", event.Path) } // Change the event to RENAME, which means it renames itself to its origin name. event.Op = RENAME @@ -114,6 +116,8 @@ func (w *Watcher) startEventLoop() { // We need no worry about the repeat adding. if err := w.watcher.Add(event.Path); err != nil { intlog.Error(err) + } else { + intlog.Printf("fake rename event, watcher re-adds monitor for: %s", event.Path) } // Change the event to CHMOD. event.Op = CHMOD @@ -130,6 +134,8 @@ func (w *Watcher) startEventLoop() { if fileIsDir(subPath) { if err := w.watcher.Add(subPath); err != nil { intlog.Error(err) + } else { + intlog.Printf("folder creation event, watcher adds monitor for: %s", subPath) } } } @@ -137,6 +143,8 @@ func (w *Watcher) startEventLoop() { // If it's a file, it directly adds it to monitor. if err := w.watcher.Add(event.Path); err != nil { intlog.Error(err) + } else { + intlog.Printf("file creation event, watcher adds monitor for: %s", event.Path) } } diff --git a/os/glog/glog_logger_config.go b/os/glog/glog_logger_config.go index e68e62342..1e387f225 100644 --- a/os/glog/glog_logger_config.go +++ b/os/glog/glog_logger_config.go @@ -57,7 +57,7 @@ func (l *Logger) SetConfig(config Config) error { return err } } - intlog.Print(l.config) + intlog.Printf("SetConfig: %+v", l.config) return nil } diff --git a/os/gres/gres_resource.go b/os/gres/gres_resource.go index 757fb83ac..ae5489e08 100644 --- a/os/gres/gres_resource.go +++ b/os/gres/gres_resource.go @@ -8,6 +8,7 @@ package gres import ( "fmt" + "github.com/gogf/gf/internal/intlog" "os" "path/filepath" "strings" @@ -41,6 +42,7 @@ func New() *Resource { func (r *Resource) Add(content string, prefix ...string) error { files, err := UnpackContent(content) if err != nil { + intlog.Printf("Add resource files failed: %v", err) return err } namePrefix := "" @@ -51,6 +53,7 @@ func (r *Resource) Add(content string, prefix ...string) error { files[i].resource = r r.tree.Set(namePrefix+files[i].file.Name, files[i]) } + intlog.Printf("Add %d files to resource manager", r.tree.Size()) return nil } diff --git a/os/gview/gview_config.go b/os/gview/gview_config.go index 629cae82d..f256225f5 100644 --- a/os/gview/gview_config.go +++ b/os/gview/gview_config.go @@ -30,7 +30,6 @@ type Config struct { // SetConfig sets the configuration for view. func (view *View) SetConfig(config Config) error { - intlog.Printf("%+v", config) var err error if len(config.Paths) > 0 { for _, v := range config.Paths { @@ -52,6 +51,8 @@ func (view *View) SetConfig(config Config) error { // Clear global template object cache. // It's just cache, do not hesitate clearing it. templates.Clear() + + intlog.Printf("SetConfig: %+v", view.config) return nil }