diff --git a/.example/database/gdb/mysql/gdb_value.go b/.example/database/gdb/mysql/gdb_value.go index b95918549..969c3a2d7 100644 --- a/.example/database/gdb/mysql/gdb_value.go +++ b/.example/database/gdb/mysql/gdb_value.go @@ -1,8 +1,6 @@ package main import ( - "fmt" - "github.com/gogf/gf/frame/g" ) @@ -10,11 +8,20 @@ func main() { db := g.DB() db.SetDebug(true) - r, e := db.Table("test").Where("id IN (?)", []interface{}{1, 2}).All() + //type User struct { + // Uid int + // Name *gvar.Var + //} + + //user := new(User) + ////user.Name = g.NewVar("john") + //g.Dump(gconv.Map(user)) + + _, e := db.Table("test").Data(g.Map{ + "name": nil, + }).Update() if e != nil { panic(e) } - if r != nil { - fmt.Println(r.ToList()) - } + } diff --git a/.example/other/test.go b/.example/other/test.go index 077f9b5fc..5439ff648 100644 --- a/.example/other/test.go +++ b/.example/other/test.go @@ -1,48 +1,18 @@ package main import ( - "fmt" - - "github.com/gogf/gf/os/gfile" - "github.com/gogf/gf/text/gregex" - - "github.com/gogf/gf/debug/gdebug" + "github.com/gogf/gf/container/gvar" + "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/util/gconv" ) -func main() { - cdnUrl := "http://localhost" - content := ` - - - - - -` - s, err := gregex.ReplaceStringFuncMatch(`(href|src)=['"](.+?)['"]`, content, func(match []string) string { - link := match[2] - if len(link) == 0 { - return match[0] - } - if link[0:1] != "/" && link[0:1] != "#" { - if len(link) > 10 && link[0:10] == "javascript" { - return match[0] - } - if len(link) > 7 && link[0:7] == "mailto:" { - return match[0] - } - if len(link) > 4 && link[0:4] == "http" { - return match[0] - } - link = "/" + link - } - if link[0:1] == "/" { - switch gfile.ExtName(link) { - case "png", "jpg", "jpeg", "gif", "js", "css", "otf", "eot", "ttf", "woff", "woff2": - return fmt.Sprintf(`%s="%s%s?%s"`, match[1], cdnUrl, link, gdebug.BinVersion()) - } - } - return match[0] - }) - fmt.Println(err) - fmt.Println(s) +type User struct { + Uid int + Name *gvar.Var +} + +func main() { + user := new(User) + user.Name = g.NewVar("john") + g.Dump(gconv.Map(user)) } diff --git a/container/gmap/gmap_hash_any_any_map.go b/container/gmap/gmap_hash_any_any_map.go index dd6818d1f..a84482733 100644 --- a/container/gmap/gmap_hash_any_any_map.go +++ b/container/gmap/gmap_hash_any_any_map.go @@ -9,6 +9,8 @@ package gmap import ( "encoding/json" + "github.com/gogf/gf/internal/empty" + "github.com/gogf/gf/util/gconv" "github.com/gogf/gf/container/gvar" @@ -68,6 +70,12 @@ func (m *AnyAnyMap) Map() map[interface{}]interface{} { return data } +// Data returns the underlying data map. +// Note that it's not concurrent safe using this function to access the data. +func (m *AnyAnyMap) Data() map[interface{}]interface{} { + return m.data +} + // MapStrAny returns a copy of the data of the map as map[string]interface{}. func (m *AnyAnyMap) MapStrAny() map[string]interface{} { m.mu.RLock() @@ -79,6 +87,17 @@ func (m *AnyAnyMap) MapStrAny() map[string]interface{} { return data } +// FilterEmpty deletes all key-value pair of which the value is empty. +func (m *AnyAnyMap) FilterEmpty() { + m.mu.Lock() + for k, v := range m.data { + if empty.IsEmpty(v) { + delete(m.data, k) + } + } + m.mu.Unlock() +} + // Set sets key-value to the hash map. func (m *AnyAnyMap) Set(key interface{}, val interface{}) { m.mu.Lock() diff --git a/container/gmap/gmap_hash_int_any_map.go b/container/gmap/gmap_hash_int_any_map.go index 9936e0757..9bbd33639 100644 --- a/container/gmap/gmap_hash_int_any_map.go +++ b/container/gmap/gmap_hash_int_any_map.go @@ -57,6 +57,12 @@ func (m *IntAnyMap) Clone() *IntAnyMap { return NewIntAnyMapFrom(m.Map(), !m.mu.IsSafe()) } +// Data returns the underlying data map. +// Note that it's not concurrent safe using this function to access the data. +func (m *IntAnyMap) Data() map[int]interface{} { + return m.data +} + // Map returns a copy of the data of the hash map. func (m *IntAnyMap) Map() map[int]interface{} { m.mu.RLock() diff --git a/container/gmap/gmap_hash_int_int_map.go b/container/gmap/gmap_hash_int_int_map.go index b53598cbe..0fef30484 100644 --- a/container/gmap/gmap_hash_int_int_map.go +++ b/container/gmap/gmap_hash_int_int_map.go @@ -54,6 +54,12 @@ func (m *IntIntMap) Clone() *IntIntMap { return NewIntIntMapFrom(m.Map(), !m.mu.IsSafe()) } +// Data returns the underlying data map. +// Note that it's not concurrent safe using this function to access the data. +func (m *IntIntMap) Data() map[int]int { + return m.data +} + // Map returns a copy of the data of the hash map. func (m *IntIntMap) Map() map[int]int { m.mu.RLock() diff --git a/container/gmap/gmap_hash_int_str_map.go b/container/gmap/gmap_hash_int_str_map.go index dd23bd8db..7951ad4bb 100644 --- a/container/gmap/gmap_hash_int_str_map.go +++ b/container/gmap/gmap_hash_int_str_map.go @@ -55,6 +55,12 @@ func (m *IntStrMap) Clone() *IntStrMap { return NewIntStrMapFrom(m.Map(), !m.mu.IsSafe()) } +// Data returns the underlying data map. +// Note that it's not concurrent safe using this function to access the data. +func (m *IntStrMap) Data() map[int]string { + return m.data +} + // Map returns a copy of the data of the hash map. func (m *IntStrMap) Map() map[int]string { m.mu.RLock() diff --git a/container/gmap/gmap_hash_str_any_map.go b/container/gmap/gmap_hash_str_any_map.go index 7467311b1..c85976ac8 100644 --- a/container/gmap/gmap_hash_str_any_map.go +++ b/container/gmap/gmap_hash_str_any_map.go @@ -57,6 +57,12 @@ func (m *StrAnyMap) Clone() *StrAnyMap { return NewStrAnyMapFrom(m.Map(), !m.mu.IsSafe()) } +// Data returns the underlying data map. +// Note that it's not concurrent safe using this function to access the data. +func (m *StrAnyMap) Data() map[string]interface{} { + return m.data +} + // Map returns a copy of the data of the hash map. func (m *StrAnyMap) Map() map[string]interface{} { m.mu.RLock() diff --git a/container/gmap/gmap_hash_str_int_map.go b/container/gmap/gmap_hash_str_int_map.go index d3ff9b453..66d9ae335 100644 --- a/container/gmap/gmap_hash_str_int_map.go +++ b/container/gmap/gmap_hash_str_int_map.go @@ -56,6 +56,12 @@ func (m *StrIntMap) Clone() *StrIntMap { return NewStrIntMapFrom(m.Map(), !m.mu.IsSafe()) } +// Data returns the underlying data map. +// Note that it's not concurrent safe using this function to access the data. +func (m *StrIntMap) Data() map[string]int { + return m.data +} + // Map returns a copy of the data of the hash map. func (m *StrIntMap) Map() map[string]int { m.mu.RLock() diff --git a/container/gmap/gmap_hash_str_str_map.go b/container/gmap/gmap_hash_str_str_map.go index fba6866ae..563d79995 100644 --- a/container/gmap/gmap_hash_str_str_map.go +++ b/container/gmap/gmap_hash_str_str_map.go @@ -55,6 +55,12 @@ func (m *StrStrMap) Clone() *StrStrMap { return NewStrStrMapFrom(m.Map(), !m.mu.IsSafe()) } +// Data returns the underlying data map. +// Note that it's not concurrent safe using this function to access the data. +func (m *StrStrMap) Data() map[string]string { + return m.data +} + // Map returns a copy of the data of the hash map. func (m *StrStrMap) Map() map[string]string { m.mu.RLock() diff --git a/container/gmap/gmap_z_any_any_test.go b/container/gmap/gmap_z_any_any_test.go new file mode 100644 index 000000000..ef03bd4b2 --- /dev/null +++ b/container/gmap/gmap_z_any_any_test.go @@ -0,0 +1,133 @@ +// Copyright 2017-2019 gf Author(https://github.com/gogf/gf). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with gm file, +// You can obtain one at https://github.com/gogf/gf. + +package gmap_test + +import ( + "testing" + + "github.com/gogf/gf/container/gmap" + "github.com/gogf/gf/test/gtest" +) + +func anyAnyCallBack(int, interface{}) bool { + return true +} + +func Test_AnyAnyMap_Basic(t *testing.T) { + gtest.Case(t, func() { + m := gmap.NewAnyAnyMap() + m.Set(1, 1) + + gtest.Assert(m.Get(1), 1) + gtest.Assert(m.Size(), 1) + gtest.Assert(m.IsEmpty(), false) + + gtest.Assert(m.GetOrSet(2, "2"), "2") + gtest.Assert(m.SetIfNotExist(2, "2"), false) + + gtest.Assert(m.SetIfNotExist(3, 3), true) + + gtest.Assert(m.Remove(2), "2") + gtest.Assert(m.Contains(2), false) + + gtest.AssertIN(3, m.Keys()) + gtest.AssertIN(1, m.Keys()) + gtest.AssertIN(3, m.Values()) + gtest.AssertIN(1, m.Values()) + m.Flip() + gtest.Assert(m.Map(), map[interface{}]int{1: 1, 3: 3}) + + m.Clear() + gtest.Assert(m.Size(), 0) + gtest.Assert(m.IsEmpty(), true) + + m2 := gmap.NewAnyAnyMapFrom(map[interface{}]interface{}{1: 1, 2: "2"}) + gtest.Assert(m2.Map(), map[interface{}]interface{}{1: 1, 2: "2"}) + }) +} + +func Test_AnyAnyMap_Set_Fun(t *testing.T) { + m := gmap.NewAnyAnyMap() + + m.GetOrSetFunc(1, getAny) + m.GetOrSetFuncLock(2, getAny) + gtest.Assert(m.Get(1), 123) + gtest.Assert(m.Get(2), 123) + + gtest.Assert(m.SetIfNotExistFunc(1, getAny), false) + gtest.Assert(m.SetIfNotExistFunc(3, getAny), true) + + gtest.Assert(m.SetIfNotExistFuncLock(2, getAny), false) + gtest.Assert(m.SetIfNotExistFuncLock(4, getAny), true) + +} + +func Test_AnyAnyMap_Batch(t *testing.T) { + m := gmap.NewAnyAnyMap() + + m.Sets(map[interface{}]interface{}{1: 1, 2: "2", 3: 3}) + gtest.Assert(m.Map(), map[interface{}]interface{}{1: 1, 2: "2", 3: 3}) + m.Removes([]interface{}{1, 2}) + gtest.Assert(m.Map(), map[interface{}]interface{}{3: 3}) +} + +func Test_AnyAnyMap_Iterator(t *testing.T) { + expect := map[interface{}]interface{}{1: 1, 2: "2"} + m := gmap.NewAnyAnyMapFrom(expect) + m.Iterator(func(k interface{}, v interface{}) bool { + gtest.Assert(expect[k], v) + return true + }) + // 断言返回值对遍历控制 + i := 0 + j := 0 + m.Iterator(func(k interface{}, v interface{}) bool { + i++ + return true + }) + m.Iterator(func(k interface{}, v interface{}) bool { + j++ + return false + }) + gtest.Assert(i, "2") + gtest.Assert(j, 1) + +} + +func Test_AnyAnyMap_Lock(t *testing.T) { + expect := map[interface{}]interface{}{1: 1, 2: "2"} + m := gmap.NewAnyAnyMapFrom(expect) + m.LockFunc(func(m map[interface{}]interface{}) { + gtest.Assert(m, expect) + }) + m.RLockFunc(func(m map[interface{}]interface{}) { + gtest.Assert(m, expect) + }) +} + +func Test_AnyAnyMap_Clone(t *testing.T) { + //clone 方法是深克隆 + m := gmap.NewAnyAnyMapFrom(map[interface{}]interface{}{1: 1, 2: "2"}) + + m_clone := m.Clone() + m.Remove(1) + //修改原 map,clone 后的 map 不影响 + gtest.AssertIN(1, m_clone.Keys()) + + m_clone.Remove(2) + //修改clone map,原 map 不影响 + gtest.AssertIN(2, m.Keys()) +} + +func Test_AnyAnyMap_Merge(t *testing.T) { + m1 := gmap.NewAnyAnyMap() + m2 := gmap.NewAnyAnyMap() + m1.Set(1, 1) + m2.Set(2, "2") + m1.Merge(m2) + gtest.Assert(m1.Map(), map[interface{}]interface{}{1: 1, 2: "2"}) +} diff --git a/container/gvar/gvar.go b/container/gvar/gvar.go index c22dbd292..895a8c8eb 100644 --- a/container/gvar/gvar.go +++ b/container/gvar/gvar.go @@ -56,6 +56,9 @@ func (v *Var) Set(value interface{}) (old interface{}) { // Val returns the current value of . func (v *Var) Val() interface{} { + if v == nil { + return nil + } if v.safe { return v.value.(*gtype.Interface).Val() } diff --git a/database/gdb/gdb_model.go b/database/gdb/gdb_model.go index 30ce8a2e7..308e314bb 100644 --- a/database/gdb/gdb_model.go +++ b/database/gdb/gdb_model.go @@ -43,6 +43,8 @@ type Model struct { const ( gLINK_TYPE_MASTER = 1 // 主节点类型 gLINK_TYPE_SLAVE = 2 // 从节点类型 + OPTION_OMITEMPTY = 1 << iota + OPTION_ALLOWEMPTY ) // 链式操作,数据表字段,可支持多个表,以半角逗号连接 diff --git a/net/ghttp/ghttp_server_config.go b/net/ghttp/ghttp_server_config.go index 7c7142d29..d71c04570 100644 --- a/net/ghttp/ghttp_server_config.go +++ b/net/ghttp/ghttp_server_config.go @@ -24,13 +24,12 @@ import ( ) const ( - gDEFAULT_HTTP_ADDR = ":80" // 默认HTTP监听地址 - gDEFAULT_HTTPS_ADDR = ":443" // 默认HTTPS监听地址 - URI_TYPE_DEFAULT = 0 // 服务注册时对象和方法名称转换为URI时,全部转为小写,单词以'-'连接符号连接 - URI_TYPE_FULLNAME = 1 // 不处理名称,以原有名称构建成URI - URI_TYPE_ALLLOWER = 2 // 仅转为小写,单词间不使用连接符号 - URI_TYPE_CAMEL = 3 // 采用驼峰命名方式 - gCHANGE_CONFIG_WHILE_RUNNING_ERROR = "server's configuration cannot be changed while running" + gDEFAULT_HTTP_ADDR = ":80" // 默认HTTP监听地址 + gDEFAULT_HTTPS_ADDR = ":443" // 默认HTTPS监听地址 + URI_TYPE_DEFAULT = 0 // 服务注册时对象和方法名称转换为URI时,全部转为小写,单词以'-'连接符号连接 + URI_TYPE_FULLNAME = 1 // 不处理名称,以原有名称构建成URI + URI_TYPE_ALLLOWER = 2 // 仅转为小写,单词间不使用连接符号 + URI_TYPE_CAMEL = 3 // 采用驼峰命名方式 ) // 自定义日志处理方法类型 @@ -125,45 +124,31 @@ func ConfigFromMap(m map[string]interface{}) ServerConfig { // http server setting设置。 // 注意使用该方法进行http server配置时,需要配置所有的配置项,否则没有配置的属性将会默认变量为空 -func (s *Server) SetConfig(c ServerConfig) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } +func (s *Server) SetConfig(c ServerConfig) error { if c.Handler == nil { c.Handler = http.HandlerFunc(s.defaultHttpHandle) } s.config = c if c.LogPath != "" { - s.logger.SetPath(c.LogPath) + return s.logger.SetPath(c.LogPath) } + return nil } // 通过map设置http server setting。 // 注意使用该方法进行http server配置时,需要配置所有的配置项,否则没有配置的属性将会默认变量为空 func (s *Server) SetConfigWithMap(m map[string]interface{}) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.SetConfig(ConfigFromMap(m)) } // 设置http server参数 - Addr func (s *Server) SetAddr(address string) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.Addr = address } // 设置http server参数 - Port func (s *Server) SetPort(port ...int) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error("config cannot be changed while running") - } if len(port) > 0 { s.config.Addr = "" for _, v := range port { @@ -177,19 +162,11 @@ func (s *Server) SetPort(port ...int) { // 设置http server参数 - HTTPS Addr func (s *Server) SetHTTPSAddr(address string) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.HTTPSAddr = address } // 设置http server参数 - HTTPS Port func (s *Server) SetHTTPSPort(port ...int) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } if len(port) > 0 { s.config.HTTPSAddr = "" for _, v := range port { @@ -203,10 +180,6 @@ func (s *Server) SetHTTPSPort(port ...int) { // 开启HTTPS支持,但是必须提供Cert和Key文件,tlsConfig为可选项 func (s *Server) EnableHTTPS(certFile, keyFile string, tlsConfig ...tls.Config) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } certFileRealPath := gfile.RealPath(certFile) if certFileRealPath == "" { certFileRealPath = gfile.RealPath(gfile.Pwd() + gfile.Separator + certFile) @@ -236,74 +209,41 @@ func (s *Server) EnableHTTPS(certFile, keyFile string, tlsConfig ...tls.Config) // 设置TLS配置对象 func (s *Server) SetTLSConfig(tlsConfig tls.Config) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.TLSConfig = tlsConfig } // 设置http server参数 - ReadTimeout func (s *Server) SetReadTimeout(t time.Duration) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.ReadTimeout = t } // 设置http server参数 - WriteTimeout func (s *Server) SetWriteTimeout(t time.Duration) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.WriteTimeout = t } // 设置http server参数 - IdleTimeout func (s *Server) SetIdleTimeout(t time.Duration) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.IdleTimeout = t } // 设置http server参数 - MaxHeaderBytes func (s *Server) SetMaxHeaderBytes(b int) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.MaxHeaderBytes = b - } // 设置http server参数 - ServerAgent func (s *Server) SetServerAgent(agent string) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.ServerAgent = agent } // 设置KeepAlive func (s *Server) SetKeepAlive(enabled bool) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.KeepAlive = enabled } // 设置模板引擎对象 func (s *Server) SetView(view *gview.View) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.View = view } diff --git a/net/ghttp/ghttp_server_config_cookie.go b/net/ghttp/ghttp_server_config_cookie.go index f629f906a..15eb58bfd 100644 --- a/net/ghttp/ghttp_server_config_cookie.go +++ b/net/ghttp/ghttp_server_config_cookie.go @@ -8,34 +8,20 @@ package ghttp import ( "time" - - "github.com/gogf/gf/os/glog" ) // 设置http server参数 - CookieMaxAge func (s *Server) SetCookieMaxAge(ttl time.Duration) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.CookieMaxAge = ttl } // 设置http server参数 - CookiePath func (s *Server) SetCookiePath(path string) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.CookiePath = path } // 设置http server参数 - CookieDomain func (s *Server) SetCookieDomain(domain string) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.CookieDomain = domain } diff --git a/net/ghttp/ghttp_server_config_logging.go b/net/ghttp/ghttp_server_config_logging.go index ab24e97ca..e985875cf 100644 --- a/net/ghttp/ghttp_server_config_logging.go +++ b/net/ghttp/ghttp_server_config_logging.go @@ -6,69 +6,43 @@ package ghttp -import ( - "github.com/gogf/gf/os/glog" -) - // 设置日志目录,只有在设置了日志目录的情况下才会输出日志到日志文件中。 // 日志文件路径格式为: // 1. 请求日志: access/YYYY-MM-DD.log // 2. 错误日志: error/YYYY-MM-DD.log func (s *Server) SetLogPath(path string) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } if len(path) == 0 { return } s.config.LogPath = path + s.config.ErrorLogEnabled = true + s.config.AccessLogEnabled = true s.logger.SetPath(path) } // 设置日志内容是否输出到终端,默认情况下只有错误日志才会自动输出到终端。 // 如果需要输出请求日志到终端,默认情况下使用SetAccessLogEnabled方法开启请求日志特性即可。 func (s *Server) SetLogStdout(enabled bool) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.LogStdout = enabled } // 设置是否开启access log日志功能 func (s *Server) SetAccessLogEnabled(enabled bool) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.AccessLogEnabled = enabled } // 设置是否开启error log日志功能 func (s *Server) SetErrorLogEnabled(enabled bool) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.ErrorLogEnabled = enabled } // 设置是否开启error stack打印功能 func (s *Server) SetErrorStack(enabled bool) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.ErrorStack = enabled } // 设置日志写入的回调函数 func (s *Server) SetLogHandler(handler LogHandler) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.LogHandler = handler } diff --git a/net/ghttp/ghttp_server_config_mess.go b/net/ghttp/ghttp_server_config_mess.go index 659beed04..ed3824ff0 100644 --- a/net/ghttp/ghttp_server_config_mess.go +++ b/net/ghttp/ghttp_server_config_mess.go @@ -6,47 +6,25 @@ package ghttp -import "github.com/gogf/gf/os/glog" - func (s *Server) SetGzipContentTypes(types []string) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.GzipContentTypes = types } // 服务注册时对象和方法名称转换为URI时的规则 func (s *Server) SetNameToUriType(t int) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.NameToUriType = t } // 是否在程序启动时打印路由表信息 func (s *Server) SetDumpRouteMap(enabled bool) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.DumpRouteMap = enabled } // 设置路由缓存过期时间(秒) func (s *Server) SetRouterCacheExpire(expire int) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.RouterCacheExpire = expire } func (s *Server) SetFormParsingMemory(maxMemory int64) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.FormParsingMemory = maxMemory } diff --git a/net/ghttp/ghttp_server_config_route.go b/net/ghttp/ghttp_server_config_route.go index c9d91e734..2762b8923 100644 --- a/net/ghttp/ghttp_server_config_route.go +++ b/net/ghttp/ghttp_server_config_route.go @@ -6,47 +6,25 @@ package ghttp -import "github.com/gogf/gf/os/glog" - func (s *Server) SetDenyIps(ips []string) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.DenyIps = ips } func (s *Server) SetAllowIps(ips []string) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.AllowIps = ips } func (s *Server) SetDenyRoutes(routes []string) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.DenyRoutes = routes } // 设置URI重写规则 func (s *Server) SetRewrite(uri string, rewrite string) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.Rewrites[uri] = rewrite } // 设置URI重写规则(批量) func (s *Server) SetRewriteMap(rewrites map[string]string) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } for k, v := range rewrites { s.config.Rewrites[k] = v } diff --git a/net/ghttp/ghttp_server_config_session.go b/net/ghttp/ghttp_server_config_session.go index bf127a55b..aec3d041f 100644 --- a/net/ghttp/ghttp_server_config_session.go +++ b/net/ghttp/ghttp_server_config_session.go @@ -10,35 +10,21 @@ import ( "time" "github.com/gogf/gf/os/gsession" - - "github.com/gogf/gf/os/glog" ) // 设置http server参数 - SessionMaxAge func (s *Server) SetSessionMaxAge(ttl time.Duration) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.SessionMaxAge = ttl s.sessionManager.SetTTL(ttl) } // 设置http server参数 - SessionIdName func (s *Server) SetSessionIdName(name string) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.SessionIdName = name } // 设置http server参数 - SessionStorage func (s *Server) SetSessionStorage(storage gsession.Storage) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.SessionStorage = storage s.sessionManager.SetStorage(storage) } diff --git a/net/ghttp/ghttp_server_config_static.go b/net/ghttp/ghttp_server_config_static.go index 5b15b4491..3bc6427cd 100644 --- a/net/ghttp/ghttp_server_config_static.go +++ b/net/ghttp/ghttp_server_config_static.go @@ -28,37 +28,21 @@ type staticPathItem struct { // 设置http server参数 - IndexFiles,默认展示文件,如:index.html, index.htm func (s *Server) SetIndexFiles(index []string) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.IndexFiles = index } // 允许展示访问目录的文件列表 func (s *Server) SetIndexFolder(enabled bool) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.IndexFolder = enabled } // 是否开启/关闭静态文件服务,当关闭时仅提供动态接口服务,路由性能会得到一定提升 func (s *Server) SetFileServerEnabled(enabled bool) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } s.config.FileServerEnabled = enabled } // 设置http server参数 - ServerRoot func (s *Server) SetServerRoot(root string) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } realPath := root if !gres.Contains(realPath) { if p, err := gfile.Search(root); err != nil { @@ -74,10 +58,6 @@ func (s *Server) SetServerRoot(root string) { // 添加静态文件搜索**目录**,必须给定目录的绝对路径 func (s *Server) AddSearchPath(path string) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } realPath := path if !gres.Contains(realPath) { if p, err := gfile.Search(path); err != nil { @@ -92,10 +72,6 @@ func (s *Server) AddSearchPath(path string) { // 添加URI与静态**目录**的映射 func (s *Server) AddStaticPath(prefix string, path string) { - if s.Status() == SERVER_STATUS_RUNNING { - glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR) - return - } realPath := path if !gres.Contains(realPath) { if p, err := gfile.Search(path); err != nil {