diff --git a/.example/net/ghttp/client/upload-batch/server.go b/.example/net/ghttp/client/upload-batch/server.go index d3a83eeb0..d7e7a2839 100644 --- a/.example/net/ghttp/client/upload-batch/server.go +++ b/.example/net/ghttp/client/upload-batch/server.go @@ -10,7 +10,7 @@ import ( // Upload uploads files to /tmp . func Upload(r *ghttp.Request) { saveDir := "/tmp/" - for _, item := range r.GetMultiPartFiles("upload-file") { + for _, item := range r.GetMultipartFiles("upload-file") { file, err := item.Open() if err != nil { r.Response.Write(err) diff --git a/.example/net/ghttp/client/upload/server.go b/.example/net/ghttp/client/upload/server.go index d3a83eeb0..d7e7a2839 100644 --- a/.example/net/ghttp/client/upload/server.go +++ b/.example/net/ghttp/client/upload/server.go @@ -10,7 +10,7 @@ import ( // Upload uploads files to /tmp . func Upload(r *ghttp.Request) { saveDir := "/tmp/" - for _, item := range r.GetMultiPartFiles("upload-file") { + for _, item := range r.GetMultipartFiles("upload-file") { file, err := item.Open() if err != nil { r.Response.Write(err) diff --git a/.example/net/ghttp/server/template/tpl1/index.html b/.example/net/ghttp/server/template/tpl1/index.tpl similarity index 79% rename from .example/net/ghttp/server/template/tpl1/index.html rename to .example/net/ghttp/server/template/tpl1/index.tpl index bebaf5f32..0dbd0a075 100644 --- a/.example/net/ghttp/server/template/tpl1/index.html +++ b/.example/net/ghttp/server/template/tpl1/index.tpl @@ -5,7 +5,6 @@ {{.title}} -

姓名 : {{.name}}

-12 +

{{.name}}: {{.score}}

\ No newline at end of file diff --git a/.example/net/ghttp/server/template/tpl1/tpl1.go b/.example/net/ghttp/server/template/tpl1/tpl1.go index e58c6cc40..b75da20c4 100644 --- a/.example/net/ghttp/server/template/tpl1/tpl1.go +++ b/.example/net/ghttp/server/template/tpl1/tpl1.go @@ -2,25 +2,19 @@ package main import ( "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/frame/gmvc" "github.com/gogf/gf/net/ghttp" ) -type ControllerIndex struct { - gmvc.Controller -} - -func (c *ControllerIndex) Info() { - c.View.Assign("title", "Go Frame 第一个网站") - c.View.Assigns(g.Map{ - "name": "很开心1", - "score": 100, - }) - c.View.Display("index.html") -} func main() { s := ghttp.GetServer() - s.BindController("/", new(ControllerIndex)) + s.BindHandler("/", func(r *ghttp.Request) { + r.Response.Write("Hello World") + r.Response.WriteTpl("index.tpl", g.Map{ + "title": "Test", + "name": "John", + "score": 100, + }) + }) s.SetPort(8199) s.Run() } diff --git a/.example/os/glog/glog_config1.go b/.example/os/glog/glog_config1.go new file mode 100644 index 000000000..fc3c5a3cb --- /dev/null +++ b/.example/os/glog/glog_config1.go @@ -0,0 +1,16 @@ +package main + +import ( + "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/os/glog" +) + +func main() { + err := glog.SetConfigWithMap(g.Map{ + "prefix": "[TEST]", + }) + if err != nil { + panic(err) + } + glog.Info(1) +} diff --git a/.example/os/glog/glog_context.go b/.example/os/glog/glog_context.go deleted file mode 100644 index f24c4572b..000000000 --- a/.example/os/glog/glog_context.go +++ /dev/null @@ -1,12 +0,0 @@ -package main - -import ( - "context" - "fmt" -) - -func main() { - c1 := context.WithValue(context.Background(), "key1", "value1") - c2 := context.WithValue(c1, "key2", "value2") - fmt.Printf("%v", c2.Value("key2")) -} diff --git a/container/gmap/gmap_hash_any_any_map.go b/container/gmap/gmap_hash_any_any_map.go index d1e43342c..2929bec0b 100644 --- a/container/gmap/gmap_hash_any_any_map.go +++ b/container/gmap/gmap_hash_any_any_map.go @@ -201,7 +201,7 @@ func (m *AnyAnyMap) doSetWithLockCheck(key interface{}, value interface{}) inter } // GetOrSet returns the value by key, -// or set value with given if not exist and returns this value. +// or sets value with given if it does not exist and then returns this value. func (m *AnyAnyMap) GetOrSet(key interface{}, value interface{}) interface{} { if v, ok := m.Search(key); !ok { return m.doSetWithLockCheck(key, value) @@ -211,8 +211,8 @@ func (m *AnyAnyMap) GetOrSet(key interface{}, value interface{}) interface{} { } // GetOrSetFunc returns the value by key, -// or sets value with return value of callback function if not exist -// and returns this value. +// or sets value with returned value of callback function if it does not exist +// and then returns this value. func (m *AnyAnyMap) GetOrSetFunc(key interface{}, f func() interface{}) interface{} { if v, ok := m.Search(key); !ok { return m.doSetWithLockCheck(key, f()) @@ -222,8 +222,8 @@ func (m *AnyAnyMap) GetOrSetFunc(key interface{}, f func() interface{}) interfac } // GetOrSetFuncLock returns the value by key, -// or sets value with return value of callback function if not exist -// and returns this value. +// or sets value with returned value of callback function if it does not exist +// and then returns this value. // // GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function // with mutex.Lock of the hash map. @@ -259,7 +259,7 @@ func (m *AnyAnyMap) GetVarOrSetFuncLock(key interface{}, f func() interface{}) * return gvar.New(m.GetOrSetFuncLock(key, f)) } -// SetIfNotExist sets to the map if the does not exist, then return true. +// SetIfNotExist sets to the map if the does not exist, and then returns true. // It returns false if exists, and would be ignored. func (m *AnyAnyMap) SetIfNotExist(key interface{}, value interface{}) bool { if !m.Contains(key) { @@ -269,7 +269,7 @@ func (m *AnyAnyMap) SetIfNotExist(key interface{}, value interface{}) bool { return false } -// SetIfNotExistFunc sets value with return value of callback function , then return true. +// SetIfNotExistFunc sets value with return value of callback function , and then returns true. // It returns false if exists, and would be ignored. func (m *AnyAnyMap) SetIfNotExistFunc(key interface{}, f func() interface{}) bool { if !m.Contains(key) { @@ -279,7 +279,7 @@ func (m *AnyAnyMap) SetIfNotExistFunc(key interface{}, f func() interface{}) boo return false } -// SetIfNotExistFuncLock sets value with return value of callback function , then return true. +// SetIfNotExistFuncLock sets value with return value of callback function , and then returns true. // It returns false if exists, and would be ignored. // // SetIfNotExistFuncLock differs with SetIfNotExistFunc function is that diff --git a/container/gmap/gmap_hash_int_any_map.go b/container/gmap/gmap_hash_int_any_map.go index 600065c7e..c3eae2d8e 100644 --- a/container/gmap/gmap_hash_int_any_map.go +++ b/container/gmap/gmap_hash_int_any_map.go @@ -201,7 +201,7 @@ func (m *IntAnyMap) doSetWithLockCheck(key int, value interface{}) interface{} { } // GetOrSet returns the value by key, -// or set value with given if not exist and returns this value. +// or sets value with given if it does not exist and then returns this value. func (m *IntAnyMap) GetOrSet(key int, value interface{}) interface{} { if v, ok := m.Search(key); !ok { return m.doSetWithLockCheck(key, value) @@ -211,7 +211,7 @@ func (m *IntAnyMap) GetOrSet(key int, value interface{}) interface{} { } // GetOrSetFunc returns the value by key, -// or sets value with return value of callback function if not exist and returns this value. +// or sets value with returned value of callback function if it does not exist and returns this value. func (m *IntAnyMap) GetOrSetFunc(key int, f func() interface{}) interface{} { if v, ok := m.Search(key); !ok { return m.doSetWithLockCheck(key, f()) @@ -221,7 +221,7 @@ func (m *IntAnyMap) GetOrSetFunc(key int, f func() interface{}) interface{} { } // GetOrSetFuncLock returns the value by key, -// or sets value with return value of callback function if not exist and returns this value. +// or sets value with returned value of callback function if it does not exist and returns this value. // // GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function // with mutex.Lock of the hash map. @@ -257,7 +257,7 @@ func (m *IntAnyMap) GetVarOrSetFuncLock(key int, f func() interface{}) *gvar.Var return gvar.New(m.GetOrSetFuncLock(key, f)) } -// SetIfNotExist sets to the map if the does not exist, then return true. +// SetIfNotExist sets to the map if the does not exist, and then returns true. // It returns false if exists, and would be ignored. func (m *IntAnyMap) SetIfNotExist(key int, value interface{}) bool { if !m.Contains(key) { @@ -267,7 +267,7 @@ func (m *IntAnyMap) SetIfNotExist(key int, value interface{}) bool { return false } -// SetIfNotExistFunc sets value with return value of callback function , then return true. +// SetIfNotExistFunc sets value with return value of callback function , and then returns true. // It returns false if exists, and would be ignored. func (m *IntAnyMap) SetIfNotExistFunc(key int, f func() interface{}) bool { if !m.Contains(key) { @@ -277,7 +277,7 @@ func (m *IntAnyMap) SetIfNotExistFunc(key int, f func() interface{}) bool { return false } -// SetIfNotExistFuncLock sets value with return value of callback function , then return true. +// SetIfNotExistFuncLock sets value with return value of callback function , and then returns true. // It returns false if exists, and would be ignored. // // SetIfNotExistFuncLock differs with SetIfNotExistFunc function is that diff --git a/container/gmap/gmap_hash_int_int_map.go b/container/gmap/gmap_hash_int_int_map.go index 249553ec1..abd89fccc 100644 --- a/container/gmap/gmap_hash_int_int_map.go +++ b/container/gmap/gmap_hash_int_int_map.go @@ -191,7 +191,7 @@ func (m *IntIntMap) doSetWithLockCheck(key int, value int) int { } // GetOrSet returns the value by key, -// or set value with given if not exist and returns this value. +// or sets value with given if it does not exist and then returns this value. func (m *IntIntMap) GetOrSet(key int, value int) int { if v, ok := m.Search(key); !ok { return m.doSetWithLockCheck(key, value) @@ -201,7 +201,7 @@ func (m *IntIntMap) GetOrSet(key int, value int) int { } // GetOrSetFunc returns the value by key, -// or sets value with return value of callback function if not exist and returns this value. +// or sets value with returned value of callback function if it does not exist and returns this value. func (m *IntIntMap) GetOrSetFunc(key int, f func() int) int { if v, ok := m.Search(key); !ok { return m.doSetWithLockCheck(key, f()) @@ -211,7 +211,7 @@ func (m *IntIntMap) GetOrSetFunc(key int, f func() int) int { } // GetOrSetFuncLock returns the value by key, -// or sets value with return value of callback function if not exist and returns this value. +// or sets value with returned value of callback function if it does not exist and returns this value. // // GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function // with mutex.Lock of the hash map. @@ -230,7 +230,7 @@ func (m *IntIntMap) GetOrSetFuncLock(key int, f func() int) int { } } -// SetIfNotExist sets to the map if the does not exist, then return true. +// SetIfNotExist sets to the map if the does not exist, and then returns true. // It returns false if exists, and would be ignored. func (m *IntIntMap) SetIfNotExist(key int, value int) bool { if !m.Contains(key) { @@ -240,7 +240,7 @@ func (m *IntIntMap) SetIfNotExist(key int, value int) bool { return false } -// SetIfNotExistFunc sets value with return value of callback function , then return true. +// SetIfNotExistFunc sets value with return value of callback function , and then returns true. // It returns false if exists, and would be ignored. func (m *IntIntMap) SetIfNotExistFunc(key int, f func() int) bool { if !m.Contains(key) { @@ -250,7 +250,7 @@ func (m *IntIntMap) SetIfNotExistFunc(key int, f func() int) bool { return false } -// SetIfNotExistFuncLock sets value with return value of callback function , then return true. +// SetIfNotExistFuncLock sets value with return value of callback function , and then returns true. // It returns false if exists, and would be ignored. // // SetIfNotExistFuncLock differs with SetIfNotExistFunc function is that diff --git a/container/gmap/gmap_hash_int_str_map.go b/container/gmap/gmap_hash_int_str_map.go index ea4ac883a..785702fe9 100644 --- a/container/gmap/gmap_hash_int_str_map.go +++ b/container/gmap/gmap_hash_int_str_map.go @@ -190,7 +190,7 @@ func (m *IntStrMap) doSetWithLockCheck(key int, value string) string { } // GetOrSet returns the value by key, -// or set value with given if not exist and returns this value. +// or sets value with given if it does not exist and then returns this value. func (m *IntStrMap) GetOrSet(key int, value string) string { if v, ok := m.Search(key); !ok { return m.doSetWithLockCheck(key, value) @@ -200,7 +200,7 @@ func (m *IntStrMap) GetOrSet(key int, value string) string { } // GetOrSetFunc returns the value by key, -// or sets value with return value of callback function if not exist and returns this value. +// or sets value with returned value of callback function if it does not exist and returns this value. func (m *IntStrMap) GetOrSetFunc(key int, f func() string) string { if v, ok := m.Search(key); !ok { return m.doSetWithLockCheck(key, f()) @@ -210,7 +210,7 @@ func (m *IntStrMap) GetOrSetFunc(key int, f func() string) string { } // GetOrSetFuncLock returns the value by key, -// or sets value with return value of callback function if not exist and returns this value. +// or sets value with returned value of callback function if it does not exist and returns this value. // // GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function // with mutex.Lock of the hash map. @@ -231,7 +231,7 @@ func (m *IntStrMap) GetOrSetFuncLock(key int, f func() string) string { } } -// SetIfNotExist sets to the map if the does not exist, then return true. +// SetIfNotExist sets to the map if the does not exist, and then returns true. // It returns false if exists, and would be ignored. func (m *IntStrMap) SetIfNotExist(key int, value string) bool { if !m.Contains(key) { @@ -241,7 +241,7 @@ func (m *IntStrMap) SetIfNotExist(key int, value string) bool { return false } -// SetIfNotExistFunc sets value with return value of callback function , then return true. +// SetIfNotExistFunc sets value with return value of callback function , and then returns true. // It returns false if exists, and would be ignored. func (m *IntStrMap) SetIfNotExistFunc(key int, f func() string) bool { if !m.Contains(key) { @@ -251,7 +251,7 @@ func (m *IntStrMap) SetIfNotExistFunc(key int, f func() string) bool { return false } -// SetIfNotExistFuncLock sets value with return value of callback function , then return true. +// SetIfNotExistFuncLock sets value with return value of callback function , and then returns true. // It returns false if exists, and would be ignored. // // SetIfNotExistFuncLock differs with SetIfNotExistFunc function is that diff --git a/container/gmap/gmap_hash_str_any_map.go b/container/gmap/gmap_hash_str_any_map.go index 054c4c90e..fecc5fe1d 100644 --- a/container/gmap/gmap_hash_str_any_map.go +++ b/container/gmap/gmap_hash_str_any_map.go @@ -195,7 +195,7 @@ func (m *StrAnyMap) doSetWithLockCheck(key string, value interface{}) interface{ } // GetOrSet returns the value by key, -// or set value with given if not exist and returns this value. +// or sets value with given if it does not exist and then returns this value. func (m *StrAnyMap) GetOrSet(key string, value interface{}) interface{} { if v, ok := m.Search(key); !ok { return m.doSetWithLockCheck(key, value) @@ -205,8 +205,8 @@ func (m *StrAnyMap) GetOrSet(key string, value interface{}) interface{} { } // GetOrSetFunc returns the value by key, -// or sets value with return value of callback function if not exist -// and returns this value. +// or sets value with returned value of callback function if it does not exist +// and then returns this value. func (m *StrAnyMap) GetOrSetFunc(key string, f func() interface{}) interface{} { if v, ok := m.Search(key); !ok { return m.doSetWithLockCheck(key, f()) @@ -216,8 +216,8 @@ func (m *StrAnyMap) GetOrSetFunc(key string, f func() interface{}) interface{} { } // GetOrSetFuncLock returns the value by key, -// or sets value with return value of callback function if not exist -// and returns this value. +// or sets value with returned value of callback function if it does not exist +// and then returns this value. // // GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function // with mutex.Lock of the hash map. @@ -253,7 +253,7 @@ func (m *StrAnyMap) GetVarOrSetFuncLock(key string, f func() interface{}) *gvar. return gvar.New(m.GetOrSetFuncLock(key, f)) } -// SetIfNotExist sets to the map if the does not exist, then return true. +// SetIfNotExist sets to the map if the does not exist, and then returns true. // It returns false if exists, and would be ignored. func (m *StrAnyMap) SetIfNotExist(key string, value interface{}) bool { if !m.Contains(key) { @@ -263,7 +263,7 @@ func (m *StrAnyMap) SetIfNotExist(key string, value interface{}) bool { return false } -// SetIfNotExistFunc sets value with return value of callback function , then return true. +// SetIfNotExistFunc sets value with return value of callback function , and then returns true. // It returns false if exists, and would be ignored. func (m *StrAnyMap) SetIfNotExistFunc(key string, f func() interface{}) bool { if !m.Contains(key) { @@ -273,7 +273,7 @@ func (m *StrAnyMap) SetIfNotExistFunc(key string, f func() interface{}) bool { return false } -// SetIfNotExistFuncLock sets value with return value of callback function , then return true. +// SetIfNotExistFuncLock sets value with return value of callback function , and then returns true. // It returns false if exists, and would be ignored. // // SetIfNotExistFuncLock differs with SetIfNotExistFunc function is that diff --git a/container/gmap/gmap_hash_str_int_map.go b/container/gmap/gmap_hash_str_int_map.go index 66734c19e..732a77b35 100644 --- a/container/gmap/gmap_hash_str_int_map.go +++ b/container/gmap/gmap_hash_str_int_map.go @@ -191,7 +191,7 @@ func (m *StrIntMap) doSetWithLockCheck(key string, value int) int { } // GetOrSet returns the value by key, -// or set value with given if not exist and returns this value. +// or sets value with given if it does not exist and then returns this value. func (m *StrIntMap) GetOrSet(key string, value int) int { if v, ok := m.Search(key); !ok { return m.doSetWithLockCheck(key, value) @@ -201,8 +201,8 @@ func (m *StrIntMap) GetOrSet(key string, value int) int { } // GetOrSetFunc returns the value by key, -// or sets value with return value of callback function if not exist -// and returns this value. +// or sets value with returned value of callback function if it does not exist +// and then returns this value. func (m *StrIntMap) GetOrSetFunc(key string, f func() int) int { if v, ok := m.Search(key); !ok { return m.doSetWithLockCheck(key, f()) @@ -212,8 +212,8 @@ func (m *StrIntMap) GetOrSetFunc(key string, f func() int) int { } // GetOrSetFuncLock returns the value by key, -// or sets value with return value of callback function if not exist -// and returns this value. +// or sets value with returned value of callback function if it does not exist +// and then returns this value. // // GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function // with mutex.Lock of the hash map. @@ -232,7 +232,7 @@ func (m *StrIntMap) GetOrSetFuncLock(key string, f func() int) int { } } -// SetIfNotExist sets to the map if the does not exist, then return true. +// SetIfNotExist sets to the map if the does not exist, and then returns true. // It returns false if exists, and would be ignored. func (m *StrIntMap) SetIfNotExist(key string, value int) bool { if !m.Contains(key) { @@ -242,7 +242,7 @@ func (m *StrIntMap) SetIfNotExist(key string, value int) bool { return false } -// SetIfNotExistFunc sets value with return value of callback function , then return true. +// SetIfNotExistFunc sets value with return value of callback function , and then returns true. // It returns false if exists, and would be ignored. func (m *StrIntMap) SetIfNotExistFunc(key string, f func() int) bool { if !m.Contains(key) { @@ -252,7 +252,7 @@ func (m *StrIntMap) SetIfNotExistFunc(key string, f func() int) bool { return false } -// SetIfNotExistFuncLock sets value with return value of callback function , then return true. +// SetIfNotExistFuncLock sets value with return value of callback function , and then returns true. // It returns false if exists, and would be ignored. // // SetIfNotExistFuncLock differs with SetIfNotExistFunc function is that diff --git a/container/gmap/gmap_hash_str_str_map.go b/container/gmap/gmap_hash_str_str_map.go index 026de7ecb..92c6a5456 100644 --- a/container/gmap/gmap_hash_str_str_map.go +++ b/container/gmap/gmap_hash_str_str_map.go @@ -190,7 +190,7 @@ func (m *StrStrMap) doSetWithLockCheck(key string, value string) string { } // GetOrSet returns the value by key, -// or set value with given if not exist and returns this value. +// or sets value with given if it does not exist and then returns this value. func (m *StrStrMap) GetOrSet(key string, value string) string { if v, ok := m.Search(key); !ok { return m.doSetWithLockCheck(key, value) @@ -200,8 +200,8 @@ func (m *StrStrMap) GetOrSet(key string, value string) string { } // GetOrSetFunc returns the value by key, -// or sets value with return value of callback function if not exist -// and returns this value. +// or sets value with returned value of callback function if it does not exist +// and then returns this value. func (m *StrStrMap) GetOrSetFunc(key string, f func() string) string { if v, ok := m.Search(key); !ok { return m.doSetWithLockCheck(key, f()) @@ -211,8 +211,8 @@ func (m *StrStrMap) GetOrSetFunc(key string, f func() string) string { } // GetOrSetFuncLock returns the value by key, -// or sets value with return value of callback function if not exist -// and returns this value. +// or sets value with returned value of callback function if it does not exist +// and then returns this value. // // GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function // with mutex.Lock of the hash map. @@ -233,7 +233,7 @@ func (m *StrStrMap) GetOrSetFuncLock(key string, f func() string) string { } } -// SetIfNotExist sets to the map if the does not exist, then return true. +// SetIfNotExist sets to the map if the does not exist, and then returns true. // It returns false if exists, and would be ignored. func (m *StrStrMap) SetIfNotExist(key string, value string) bool { if !m.Contains(key) { @@ -243,7 +243,7 @@ func (m *StrStrMap) SetIfNotExist(key string, value string) bool { return false } -// SetIfNotExistFunc sets value with return value of callback function , then return true. +// SetIfNotExistFunc sets value with return value of callback function , and then returns true. // It returns false if exists, and would be ignored. func (m *StrStrMap) SetIfNotExistFunc(key string, f func() string) bool { if !m.Contains(key) { @@ -253,7 +253,7 @@ func (m *StrStrMap) SetIfNotExistFunc(key string, f func() string) bool { return false } -// SetIfNotExistFuncLock sets value with return value of callback function , then return true. +// SetIfNotExistFuncLock sets value with return value of callback function , and then returns true. // It returns false if exists, and would be ignored. // // SetIfNotExistFuncLock differs with SetIfNotExistFunc function is that diff --git a/container/gmap/gmap_list_map.go b/container/gmap/gmap_list_map.go index bc40b3826..937dcacef 100644 --- a/container/gmap/gmap_list_map.go +++ b/container/gmap/gmap_list_map.go @@ -268,7 +268,7 @@ func (m *ListMap) doSetWithLockCheck(key interface{}, value interface{}) interfa } // GetOrSet returns the value by key, -// or set value with given if not exist and returns this value. +// or sets value with given if it does not exist and then returns this value. func (m *ListMap) GetOrSet(key interface{}, value interface{}) interface{} { if v, ok := m.Search(key); !ok { return m.doSetWithLockCheck(key, value) @@ -278,8 +278,8 @@ func (m *ListMap) GetOrSet(key interface{}, value interface{}) interface{} { } // GetOrSetFunc returns the value by key, -// or sets value with return value of callback function if not exist -// and returns this value. +// or sets value with returned value of callback function if it does not exist +// and then returns this value. func (m *ListMap) GetOrSetFunc(key interface{}, f func() interface{}) interface{} { if v, ok := m.Search(key); !ok { return m.doSetWithLockCheck(key, f()) @@ -289,8 +289,8 @@ func (m *ListMap) GetOrSetFunc(key interface{}, f func() interface{}) interface{ } // GetOrSetFuncLock returns the value by key, -// or sets value with return value of callback function if not exist -// and returns this value. +// or sets value with returned value of callback function if it does not exist +// and then returns this value. // // GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function // with mutex.Lock of the map. @@ -326,7 +326,7 @@ func (m *ListMap) GetVarOrSetFuncLock(key interface{}, f func() interface{}) *gv return gvar.New(m.GetOrSetFuncLock(key, f)) } -// SetIfNotExist sets to the map if the does not exist, then return true. +// SetIfNotExist sets to the map if the does not exist, and then returns true. // It returns false if exists, and would be ignored. func (m *ListMap) SetIfNotExist(key interface{}, value interface{}) bool { if !m.Contains(key) { @@ -336,7 +336,7 @@ func (m *ListMap) SetIfNotExist(key interface{}, value interface{}) bool { return false } -// SetIfNotExistFunc sets value with return value of callback function , then return true. +// SetIfNotExistFunc sets value with return value of callback function , and then returns true. // It returns false if exists, and would be ignored. func (m *ListMap) SetIfNotExistFunc(key interface{}, f func() interface{}) bool { if !m.Contains(key) { @@ -346,7 +346,7 @@ func (m *ListMap) SetIfNotExistFunc(key interface{}, f func() interface{}) bool return false } -// SetIfNotExistFuncLock sets value with return value of callback function , then return true. +// SetIfNotExistFuncLock sets value with return value of callback function , and then returns true. // It returns false if exists, and would be ignored. // // SetIfNotExistFuncLock differs with SetIfNotExistFunc function is that diff --git a/container/gtree/gtree_avltree.go b/container/gtree/gtree_avltree.go index 377f33671..59c337046 100644 --- a/container/gtree/gtree_avltree.go +++ b/container/gtree/gtree_avltree.go @@ -137,7 +137,7 @@ func (tree *AVLTree) doSetWithLockCheck(key interface{}, value interface{}) inte } // GetOrSet returns the value by key, -// or set value with given if not exist and returns this value. +// or sets value with given if it does not exist and then returns this value. func (tree *AVLTree) GetOrSet(key interface{}, value interface{}) interface{} { if v, ok := tree.Search(key); !ok { return tree.doSetWithLockCheck(key, value) @@ -147,8 +147,8 @@ func (tree *AVLTree) GetOrSet(key interface{}, value interface{}) interface{} { } // GetOrSetFunc returns the value by key, -// or sets value with return value of callback function if not exist -// and returns this value. +// or sets value with returned value of callback function if it does not exist +// and then returns this value. func (tree *AVLTree) GetOrSetFunc(key interface{}, f func() interface{}) interface{} { if v, ok := tree.Search(key); !ok { return tree.doSetWithLockCheck(key, f()) @@ -158,8 +158,8 @@ func (tree *AVLTree) GetOrSetFunc(key interface{}, f func() interface{}) interfa } // GetOrSetFuncLock returns the value by key, -// or sets value with return value of callback function if not exist -// and returns this value. +// or sets value with returned value of callback function if it does not exist +// and then returns this value. // // GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function // with mutex.Lock of the hash map. @@ -195,7 +195,7 @@ func (tree *AVLTree) GetVarOrSetFuncLock(key interface{}, f func() interface{}) return gvar.New(tree.GetOrSetFuncLock(key, f)) } -// SetIfNotExist sets to the map if the does not exist, then return true. +// SetIfNotExist sets to the map if the does not exist, and then returns true. // It returns false if exists, and would be ignored. func (tree *AVLTree) SetIfNotExist(key interface{}, value interface{}) bool { if !tree.Contains(key) { @@ -205,7 +205,7 @@ func (tree *AVLTree) SetIfNotExist(key interface{}, value interface{}) bool { return false } -// SetIfNotExistFunc sets value with return value of callback function , then return true. +// SetIfNotExistFunc sets value with return value of callback function , and then returns true. // It returns false if exists, and would be ignored. func (tree *AVLTree) SetIfNotExistFunc(key interface{}, f func() interface{}) bool { if !tree.Contains(key) { @@ -215,7 +215,7 @@ func (tree *AVLTree) SetIfNotExistFunc(key interface{}, f func() interface{}) bo return false } -// SetIfNotExistFuncLock sets value with return value of callback function , then return true. +// SetIfNotExistFuncLock sets value with return value of callback function , and then returns true. // It returns false if exists, and would be ignored. // // SetIfNotExistFuncLock differs with SetIfNotExistFunc function is that diff --git a/container/gtree/gtree_btree.go b/container/gtree/gtree_btree.go index 3fcad5faf..0372f9bbe 100644 --- a/container/gtree/gtree_btree.go +++ b/container/gtree/gtree_btree.go @@ -135,7 +135,7 @@ func (tree *BTree) doSetWithLockCheck(key interface{}, value interface{}) interf } // GetOrSet returns the value by key, -// or set value with given if not exist and returns this value. +// or sets value with given if it does not exist and then returns this value. func (tree *BTree) GetOrSet(key interface{}, value interface{}) interface{} { if v, ok := tree.Search(key); !ok { return tree.doSetWithLockCheck(key, value) @@ -145,8 +145,8 @@ func (tree *BTree) GetOrSet(key interface{}, value interface{}) interface{} { } // GetOrSetFunc returns the value by key, -// or sets value with return value of callback function if not exist -// and returns this value. +// or sets value with returned value of callback function if it does not exist +// and then returns this value. func (tree *BTree) GetOrSetFunc(key interface{}, f func() interface{}) interface{} { if v, ok := tree.Search(key); !ok { return tree.doSetWithLockCheck(key, f()) @@ -156,8 +156,8 @@ func (tree *BTree) GetOrSetFunc(key interface{}, f func() interface{}) interface } // GetOrSetFuncLock returns the value by key, -// or sets value with return value of callback function if not exist -// and returns this value. +// or sets value with returned value of callback function if it does not exist +// and then returns this value. // // GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function // with mutex.Lock of the hash map. @@ -193,7 +193,7 @@ func (tree *BTree) GetVarOrSetFuncLock(key interface{}, f func() interface{}) *g return gvar.New(tree.GetOrSetFuncLock(key, f)) } -// SetIfNotExist sets to the map if the does not exist, then return true. +// SetIfNotExist sets to the map if the does not exist, and then returns true. // It returns false if exists, and would be ignored. func (tree *BTree) SetIfNotExist(key interface{}, value interface{}) bool { if !tree.Contains(key) { @@ -203,7 +203,7 @@ func (tree *BTree) SetIfNotExist(key interface{}, value interface{}) bool { return false } -// SetIfNotExistFunc sets value with return value of callback function , then return true. +// SetIfNotExistFunc sets value with return value of callback function , and then returns true. // It returns false if exists, and would be ignored. func (tree *BTree) SetIfNotExistFunc(key interface{}, f func() interface{}) bool { if !tree.Contains(key) { @@ -213,7 +213,7 @@ func (tree *BTree) SetIfNotExistFunc(key interface{}, f func() interface{}) bool return false } -// SetIfNotExistFuncLock sets value with return value of callback function , then return true. +// SetIfNotExistFuncLock sets value with return value of callback function , and then returns true. // It returns false if exists, and would be ignored. // // SetIfNotExistFuncLock differs with SetIfNotExistFunc function is that diff --git a/container/gtree/gtree_redblacktree.go b/container/gtree/gtree_redblacktree.go index 34e94f9f9..6284e403a 100644 --- a/container/gtree/gtree_redblacktree.go +++ b/container/gtree/gtree_redblacktree.go @@ -177,7 +177,7 @@ func (tree *RedBlackTree) doSetWithLockCheck(key interface{}, value interface{}) } // GetOrSet returns the value by key, -// or set value with given if not exist and returns this value. +// or sets value with given if it does not exist and then returns this value. func (tree *RedBlackTree) GetOrSet(key interface{}, value interface{}) interface{} { if v, ok := tree.Search(key); !ok { return tree.doSetWithLockCheck(key, value) @@ -187,8 +187,8 @@ func (tree *RedBlackTree) GetOrSet(key interface{}, value interface{}) interface } // GetOrSetFunc returns the value by key, -// or sets value with return value of callback function if not exist -// and returns this value. +// or sets value with returned value of callback function if it does not exist +// and then returns this value. func (tree *RedBlackTree) GetOrSetFunc(key interface{}, f func() interface{}) interface{} { if v, ok := tree.Search(key); !ok { return tree.doSetWithLockCheck(key, f()) @@ -198,8 +198,8 @@ func (tree *RedBlackTree) GetOrSetFunc(key interface{}, f func() interface{}) in } // GetOrSetFuncLock returns the value by key, -// or sets value with return value of callback function if not exist -// and returns this value. +// or sets value with returned value of callback function if it does not exist +// and then returns this value. // // GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function // with mutex.Lock of the hash map. @@ -235,7 +235,7 @@ func (tree *RedBlackTree) GetVarOrSetFuncLock(key interface{}, f func() interfac return gvar.New(tree.GetOrSetFuncLock(key, f)) } -// SetIfNotExist sets to the map if the does not exist, then return true. +// SetIfNotExist sets to the map if the does not exist, and then returns true. // It returns false if exists, and would be ignored. func (tree *RedBlackTree) SetIfNotExist(key interface{}, value interface{}) bool { if !tree.Contains(key) { @@ -245,7 +245,7 @@ func (tree *RedBlackTree) SetIfNotExist(key interface{}, value interface{}) bool return false } -// SetIfNotExistFunc sets value with return value of callback function , then return true. +// SetIfNotExistFunc sets value with return value of callback function , and then returns true. // It returns false if exists, and would be ignored. func (tree *RedBlackTree) SetIfNotExistFunc(key interface{}, f func() interface{}) bool { if !tree.Contains(key) { @@ -255,7 +255,7 @@ func (tree *RedBlackTree) SetIfNotExistFunc(key interface{}, f func() interface{ return false } -// SetIfNotExistFuncLock sets value with return value of callback function , then return true. +// SetIfNotExistFuncLock sets value with return value of callback function , and then returns true. // It returns false if exists, and would be ignored. // // SetIfNotExistFuncLock differs with SetIfNotExistFunc function is that diff --git a/frame/g/g_object.go b/frame/g/g_object.go index 74e9417de..37d95232c 100644 --- a/frame/g/g_object.go +++ b/frame/g/g_object.go @@ -15,6 +15,7 @@ import ( "github.com/gogf/gf/net/gtcp" "github.com/gogf/gf/net/gudp" "github.com/gogf/gf/os/gcfg" + "github.com/gogf/gf/os/glog" "github.com/gogf/gf/os/gres" "github.com/gogf/gf/os/gview" ) @@ -68,6 +69,12 @@ func Res(name ...string) *gres.Resource { return Resource(name...) } +// Log returns an instance of glog.Logger. +// The parameter is the name for the instance. +func Log(name ...string) *glog.Logger { + return gins.Log(name...) +} + // Database returns an instance of database ORM object with specified configuration group name. func Database(name ...string) gdb.DB { return gins.Database(name...) diff --git a/frame/gins/gins.go b/frame/gins/gins.go index c7fca2926..aa8808773 100644 --- a/frame/gins/gins.go +++ b/frame/gins/gins.go @@ -27,40 +27,50 @@ import ( const ( gFRAME_CORE_COMPONENT_NAME_REDIS = "gf.core.component.redis" + gFRAME_CORE_COMPONENT_NAME_LOGGER = "gf.core.component.logger" gFRAME_CORE_COMPONENT_NAME_DATABASE = "gf.core.component.database" ) -// 单例对象存储器 +// instances is the instance map for common used components. var instances = gmap.NewStrAnyMap(true) -// 获取单例对象 -func Get(key string) interface{} { - return instances.Get(key) +// Get returns the instance by given name. +func Get(name string) interface{} { + return instances.Get(name) } -// 设置单例对象 -func Set(key string, value interface{}) { - instances.Set(key, value) +// Set sets a instance object to the instance manager with given name. +func Set(name string, instance interface{}) { + instances.Set(name, instance) } -// 当键名存在时返回其键值,否则写入指定的键值 -func GetOrSet(key string, value interface{}) interface{} { - return instances.GetOrSet(key, value) +// GetOrSet returns the instance by name, +// or set instance to the instance manager if it does not exist and returns this instance. +func GetOrSet(name string, instance interface{}) interface{} { + return instances.GetOrSet(name, instance) } -// 当键名存在时返回其键值,否则写入指定的键值,键值由指定的函数生成 -func GetOrSetFunc(key string, f func() interface{}) interface{} { - return instances.GetOrSetFunc(key, f) +// GetOrSetFunc returns the instance by name, +// or sets instance with returned value of callback function if it does not exist +// and then returns this instance. +func GetOrSetFunc(name string, f func() interface{}) interface{} { + return instances.GetOrSetFunc(name, f) } -// 与GetOrSetFunc不同的是,f是在写锁机制内执行 -func GetOrSetFuncLock(key string, f func() interface{}) interface{} { - return instances.GetOrSetFuncLock(key, f) +// GetOrSetFuncLock returns the instance by name, +// or sets instance with returned value of callback function if it does not exist +// and then returns this instance. +// +// GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function +// with mutex.Lock of the hash map. +func GetOrSetFuncLock(name string, f func() interface{}) interface{} { + return instances.GetOrSetFuncLock(name, f) } -// 当键名不存在时写入,并返回true;否则返回false。 -func SetIfNotExist(key string, value interface{}) bool { - return instances.SetIfNotExist(key, value) +// SetIfNotExist sets to the map if the does not exist, then returns true. +// It returns false if exists, and would be ignored. +func SetIfNotExist(name string, instance interface{}) bool { + return instances.SetIfNotExist(name, instance) } // View returns an instance of View with default settings. @@ -87,6 +97,26 @@ func I18n(name ...string) *gi18n.Manager { return gi18n.Instance(name...) } +// Log returns an instance of glog.Logger. +// The parameter is the name for the instance. +func Log(name ...string) *glog.Logger { + config := Config() + instanceName := glog.DEFAULT_NAME + if len(name) > 0 && name[0] != "" { + instanceName = name[0] + } + instanceKey := fmt.Sprintf("%s.%s", gFRAME_CORE_COMPONENT_NAME_LOGGER, instanceName) + return instances.GetOrSetFuncLock(instanceKey, func() interface{} { + logger := glog.Instance(instanceName) + if m := config.GetMap("logging"); m != nil { + if err := logger.SetConfigWithMap(m); err != nil { + glog.Error(err) + } + } + return logger + }).(*glog.Logger) +} + // Database returns an instance of database ORM object // with specified configuration group name. func Database(name ...string) gdb.DB { diff --git a/go.mod b/go.mod index 427ef104c..f31a22898 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/gf-third/mysql v1.4.2 github.com/gf-third/yaml v1.0.1 github.com/gomodule/redigo v2.0.0+incompatible + github.com/google/uuid v1.1.1 github.com/gorilla/websocket v1.4.1 github.com/grokify/html-strip-tags-go v0.0.0-20190921062105-daaa06bf1aaf github.com/mattn/go-runewidth v0.0.4 // indirect diff --git a/os/glog/glog_config.go b/os/glog/glog_config.go new file mode 100644 index 000000000..e41d0ce92 --- /dev/null +++ b/os/glog/glog_config.go @@ -0,0 +1,17 @@ +// Copyright 2017 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 this file, +// You can obtain one at https://github.com/gogf/gf. + +package glog + +// SetConfig set configurations for the logger. +func SetConfig(config Config) error { + return logger.SetConfig(config) +} + +// SetConfigWithMap set configurations with map for the logger. +func SetConfigWithMap(m map[string]interface{}) error { + return logger.SetConfigWithMap(m) +} diff --git a/os/glog/glog_instance.go b/os/glog/glog_instance.go new file mode 100644 index 000000000..a5bff1639 --- /dev/null +++ b/os/glog/glog_instance.go @@ -0,0 +1,31 @@ +// Copyright 2017 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 this file, +// You can obtain one at https://github.com/gogf/gf. + +package glog + +import "github.com/gogf/gf/container/gmap" + +const ( + // Default group name for instance usage. + DEFAULT_NAME = "default" +) + +var ( + // Instances map. + instances = gmap.NewStrAnyMap(true) +) + +// Instance returns an instance of Logger with default settings. +// The parameter is the name for the instance. +func Instance(name ...string) *Logger { + key := DEFAULT_NAME + if len(name) > 0 && name[0] != "" { + key = name[0] + } + return instances.GetOrSetFuncLock(key, func() interface{} { + return New() + }).(*Logger) +} diff --git a/os/glog/glog_logger_config.go b/os/glog/glog_logger_config.go index b0abd10cf..e307e894a 100644 --- a/os/glog/glog_logger_config.go +++ b/os/glog/glog_logger_config.go @@ -8,6 +8,7 @@ package glog import ( "errors" + "github.com/gogf/gf/internal/intlog" "github.com/gogf/gf/os/gfile" "github.com/gogf/gf/util/gconv" "io" @@ -25,8 +26,8 @@ type Config struct { StSkip int // Skip count for stack. StStatus int // Stack status(1: enabled - default; 0: disabled) StFilter string // Stack string filter. - HeaderPrint bool // Print header or not(true in default). - StdoutPrint bool // Output to stdout or not(true in default). + HeaderPrint bool `c:"header"` // Print header or not(true in default). + StdoutPrint bool `c:"stdout"` // Output to stdout or not(true in default). } // DefaultConfig returns the default configuration for logger. @@ -42,19 +43,41 @@ func DefaultConfig() Config { } // SetConfig set configurations for the logger. -func (l *Logger) SetConfig(config Config) { +func (l *Logger) SetConfig(config Config) error { l.config = config + // Necessary validation. + if config.Path != "" { + if err := l.SetPath(config.Path); err != nil { + intlog.Error(err) + return err + } + } + intlog.Print(l.config) + return nil } // SetConfigWithMap set configurations with map for the logger. func (l *Logger) SetConfigWithMap(m map[string]interface{}) error { - config := Config{} + if m == nil || len(m) == 0 { + return errors.New("configuration cannot be empty") + } + // Change string configuration to int value for level. + if v, ok := m["level"]; ok { + switch gconv.String(v) { + case "all": + m["level"] = LEVEL_ALL + case "dev": + m["level"] = LEVEL_DEV + case "prod": + m["level"] = LEVEL_PROD + } + } + config := DefaultConfig() err := gconv.Struct(m, &config) if err != nil { return err } - l.SetConfig(config) - return nil + return l.SetConfig(config) } // SetLevel sets the logging level. @@ -132,7 +155,7 @@ func (l *Logger) GetWriter() io.Writer { // SetPath sets the directory path for file logging. func (l *Logger) SetPath(path string) error { if path == "" { - return errors.New("path is empty") + return errors.New("logging path is empty") } if !gfile.Exists(path) { if err := gfile.Mkdir(path); err != nil { diff --git a/os/glog/glog_z_unit_test.go b/os/glog/glog_z_unit_test.go index bf968ba54..be731a0cf 100644 --- a/os/glog/glog_z_unit_test.go +++ b/os/glog/glog_z_unit_test.go @@ -15,14 +15,14 @@ func Test_SetConfigWithMap(t *testing.T) { gtest.Case(t, func() { l := New() m := map[string]interface{}{ - "path": "/tmp/log", - "level": LEVEL_PROD, - "stdout-print": true, + "path": "/tmp/log", + "level": LEVEL_PROD, + "stdout": false, } err := l.SetConfigWithMap(m) gtest.Assert(err, nil) gtest.Assert(l.config.Path, m["path"]) gtest.Assert(l.config.Level, m["level"]) - gtest.Assert(l.config.StdoutPrint, m["stdout-print"]) + gtest.Assert(l.config.StdoutPrint, m["stdout"]) }) } diff --git a/util/gutil/gutil_z_comparator_z_unit_test.go b/util/gutil/gutil_z_comparator_z_unit_test.go index c214d30f9..3020574ea 100755 --- a/util/gutil/gutil_z_comparator_z_unit_test.go +++ b/util/gutil/gutil_z_comparator_z_unit_test.go @@ -1,3 +1,9 @@ +// Copyright 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 this file, +// You can obtain one at https://github.com/gogf/gf. + package gutil_test import ( diff --git a/util/gutil/gutil_z_unit_test.go b/util/gutil/gutil_z_unit_test.go index 21b7c8090..248352e1e 100755 --- a/util/gutil/gutil_z_unit_test.go +++ b/util/gutil/gutil_z_unit_test.go @@ -1,3 +1,9 @@ +// Copyright 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 this file, +// You can obtain one at https://github.com/gogf/gf. + package gutil_test import ( diff --git a/util/guuid/guuid.go b/util/guuid/guuid.go new file mode 100644 index 000000000..e0fc1d016 --- /dev/null +++ b/util/guuid/guuid.go @@ -0,0 +1,92 @@ +// Copyright 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 this file, +// You can obtain one at https://github.com/gogf/gf. + +// Package guuid generates and inspects UUIDs. +// +// This package is a wrapper for most common used UUID package: +// https://github.com/google/uuid +package guuid + +import ( + "github.com/google/uuid" + "os" +) + +// UUID representation compliant with specification +// described in RFC 4122. +type UUID = uuid.UUID + +// UUID DCE domains. +const ( + DomainPerson = uuid.Domain(0) + DomainGroup = uuid.Domain(1) + DomainOrg = uuid.Domain(2) +) + +// New creates a new random UUID or panics. +func New() UUID { + return uuid.New() +} + +// NewUUID returns a Version 1 UUID based on the current NodeID and clock +// sequence, and the current time. If the NodeID has not been set by SetNodeID +// or SetNodeInterface then it will be set automatically. If the NodeID cannot +// be set NewUUID returns nil. If clock sequence has not been set by +// SetClockSequence then it will be set automatically. If GetTime fails to +// return the current NewUUID returns nil and an error. +// +// In most cases, New should be used. +func NewUUID() (UUID, error) { + return uuid.NewUUID() +} + +// NewDCEGroup returns a DCE Security (Version 2) UUID in the group +// domain with the id returned by os.Getgid. +// +// NewDCESecurity(Group, uint32(os.Getgid())) +func NewDCEGroup() (UUID, error) { + return uuid.NewDCESecurity(DomainGroup, uint32(os.Getgid())) +} + +// NewDCEPerson returns a DCE Security (Version 2) UUID in the person +// domain with the id returned by os.Getuid. +// +// NewDCESecurity(Person, uint32(os.Getuid())) +func NewDCEPerson() (UUID, error) { + return uuid.NewDCESecurity(DomainPerson, uint32(os.Getuid())) +} + +// NewMD5 returns a new MD5 (Version 3) UUID based on the +// supplied name space and data. It is the same as calling: +// +// NewHash(md5.New(), space, data, 3) +func NewMD5(space UUID, data []byte) UUID { + return uuid.NewMD5(space, data) +} + +// NewRandom returns a Random (Version 4) UUID. +// +// The strength of the UUIDs is based on the strength of the crypto/rand +// package. +// +// A note about uniqueness derived from the UUID Wikipedia entry: +// +// Randomly generated UUIDs have 122 random bits. One's annual risk of being +// hit by a meteorite is estimated to be one chance in 17 billion, that +// means the probability is about 0.00000000006 (6 × 10−11), +// equivalent to the odds of creating a few tens of trillions of UUIDs in a +// year and having one duplicate. +func NewRandom() (UUID, error) { + return uuid.NewRandom() +} + +// NewSHA1 returns a new SHA1 (Version 5) UUID based on the +// supplied name space and data. It is the same as calling: +// +// NewHash(sha1.New(), space, data, 5) +func NewSHA1(space UUID, data []byte) UUID { + return uuid.NewSHA1(space, data) +} diff --git a/util/guuid/guuid_test.go b/util/guuid/guuid_test.go new file mode 100755 index 000000000..469e9588e --- /dev/null +++ b/util/guuid/guuid_test.go @@ -0,0 +1,38 @@ +// Copyright 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 this file, +// You can obtain one at https://github.com/gogf/gf. + +package guuid_test + +import ( + "github.com/gogf/gf/util/guuid" + "testing" + + "github.com/gogf/gf/test/gtest" +) + +func Test_Basic(t *testing.T) { + gtest.Case(t, func() { + gtest.Assert(len(guuid.New().String()), 36) + + uuid, _ := guuid.NewUUID() + gtest.Assert(len(uuid.String()), 36) + + uuid, _ = guuid.NewDCEGroup() + gtest.Assert(len(uuid.String()), 36) + + uuid, _ = guuid.NewDCEPerson() + gtest.Assert(len(uuid.String()), 36) + + uuid, _ = guuid.NewRandom() + gtest.Assert(len(uuid.String()), 36) + + uuid, _ = guuid.NewRandom() + gtest.Assert(len(uuid.String()), 36) + + gtest.Assert(len(guuid.NewMD5(guuid.UUID{}, []byte("")).String()), 36) + gtest.Assert(len(guuid.NewSHA1(guuid.UUID{}, []byte("")).String()), 36) + }) +}