diff --git a/.example/container/garray/basic_array.go b/.example/container/garray/basic_array.go index 7a74ec957..3db377d4d 100644 --- a/.example/container/garray/basic_array.go +++ b/.example/container/garray/basic_array.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/container/garray" + "github.com/gogf/gf/v2/container/garray" ) func main() { diff --git a/.example/container/garray/json_marshal.go b/.example/container/garray/json_marshal.go index c27424c5b..4f5859413 100644 --- a/.example/container/garray/json_marshal.go +++ b/.example/container/garray/json_marshal.go @@ -3,7 +3,7 @@ package main import ( "encoding/json" "fmt" - "github.com/gogf/gf/container/garray" + "github.com/gogf/gf/v2/container/garray" ) func main() { diff --git a/.example/container/garray/json_unmarshal.go b/.example/container/garray/json_unmarshal.go index 07e81adb0..144287a99 100644 --- a/.example/container/garray/json_unmarshal.go +++ b/.example/container/garray/json_unmarshal.go @@ -3,7 +3,7 @@ package main import ( "encoding/json" "fmt" - "github.com/gogf/gf/container/garray" + "github.com/gogf/gf/v2/container/garray" ) func main() { diff --git a/.example/container/garray/sorted_array_basic.go b/.example/container/garray/sorted_array_basic.go index a1792551b..81e0531f8 100644 --- a/.example/container/garray/sorted_array_basic.go +++ b/.example/container/garray/sorted_array_basic.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/container/garray" + "github.com/gogf/gf/v2/container/garray" ) func main() { diff --git a/.example/container/garray/sorted_string_array.go b/.example/container/garray/sorted_string_array.go index 109fe31c5..a89de1f46 100644 --- a/.example/container/garray/sorted_string_array.go +++ b/.example/container/garray/sorted_string_array.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/container/garray" + "github.com/gogf/gf/v2/container/garray" ) func main() { diff --git a/.example/container/glist/basic.go b/.example/container/glist/basic.go index 73889c9ea..a904ea345 100644 --- a/.example/container/glist/basic.go +++ b/.example/container/glist/basic.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "github.com/gogf/gf/container/glist" + "github.com/gogf/gf/v2/container/glist" ) func main() { diff --git a/.example/container/glist/json_marshal.go b/.example/container/glist/json_marshal.go index f6daafa06..00cc3409b 100644 --- a/.example/container/glist/json_marshal.go +++ b/.example/container/glist/json_marshal.go @@ -3,8 +3,8 @@ package main import ( "encoding/json" "fmt" - "github.com/gogf/gf/container/glist" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/container/glist" + "github.com/gogf/gf/v2/frame/g" ) func main() { diff --git a/.example/container/glist/json_unmarshal.go b/.example/container/glist/json_unmarshal.go index 313dfe570..7b03f7cff 100644 --- a/.example/container/glist/json_unmarshal.go +++ b/.example/container/glist/json_unmarshal.go @@ -3,7 +3,7 @@ package main import ( "encoding/json" "fmt" - "github.com/gogf/gf/container/glist" + "github.com/gogf/gf/v2/container/glist" ) func main() { diff --git a/.example/container/gmap/basic.go b/.example/container/gmap/basic.go index 4fb984930..4d9b5a453 100644 --- a/.example/container/gmap/basic.go +++ b/.example/container/gmap/basic.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/container/gmap" + "github.com/gogf/gf/v2/container/gmap" ) func main() { diff --git a/.example/container/gmap/gmap_json_marshal.go b/.example/container/gmap/gmap_json_marshal.go index 1aae8c385..76ac64630 100644 --- a/.example/container/gmap/gmap_json_marshal.go +++ b/.example/container/gmap/gmap_json_marshal.go @@ -3,9 +3,9 @@ package main import ( "encoding/json" "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" - "github.com/gogf/gf/container/gmap" + "github.com/gogf/gf/v2/container/gmap" ) func main() { diff --git a/.example/container/gmap/gmap_json_unmarshal.go b/.example/container/gmap/gmap_json_unmarshal.go index af3c134a8..7f5a9d24a 100644 --- a/.example/container/gmap/gmap_json_unmarshal.go +++ b/.example/container/gmap/gmap_json_unmarshal.go @@ -3,7 +3,7 @@ package main import ( "encoding/json" "fmt" - "github.com/gogf/gf/container/gmap" + "github.com/gogf/gf/v2/container/gmap" ) func main() { diff --git a/.example/container/gmap/gmap_map_clone_safe.go b/.example/container/gmap/gmap_map_clone_safe.go index 95a8662d5..912ea9eff 100644 --- a/.example/container/gmap/gmap_map_clone_safe.go +++ b/.example/container/gmap/gmap_map_clone_safe.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/container/gmap" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/container/gmap" + "github.com/gogf/gf/v2/frame/g" ) func main() { diff --git a/.example/container/gmap/gmap_maps.go b/.example/container/gmap/gmap_maps.go index 9054ac70c..7b7267b1b 100644 --- a/.example/container/gmap/gmap_maps.go +++ b/.example/container/gmap/gmap_maps.go @@ -3,9 +3,9 @@ package main import ( "fmt" - "github.com/gogf/gf/container/gmap" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/util/gutil" + "github.com/gogf/gf/v2/container/gmap" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/util/gutil" ) func main() { diff --git a/.example/container/gmap/gmap_treemap.go b/.example/container/gmap/gmap_treemap.go index 262dd1219..d495ac336 100644 --- a/.example/container/gmap/gmap_treemap.go +++ b/.example/container/gmap/gmap_treemap.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/container/gmap" - "github.com/gogf/gf/util/gutil" + "github.com/gogf/gf/v2/container/gmap" + "github.com/gogf/gf/v2/util/gutil" ) func main() { diff --git a/.example/container/gpool/gpool.go b/.example/container/gpool/gpool.go index 771c12edf..a027dcba5 100644 --- a/.example/container/gpool/gpool.go +++ b/.example/container/gpool/gpool.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/gogf/gf/container/gpool" + "github.com/gogf/gf/v2/container/gpool" ) func main() { diff --git a/.example/container/gpool/gpool_expirefunc.go b/.example/container/gpool/gpool_expirefunc.go index cc490b1d4..36ded0980 100644 --- a/.example/container/gpool/gpool_expirefunc.go +++ b/.example/container/gpool/gpool_expirefunc.go @@ -4,9 +4,9 @@ import ( "fmt" "time" - "github.com/gogf/gf/container/gpool" - "github.com/gogf/gf/net/gtcp" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/container/gpool" + "github.com/gogf/gf/v2/net/gtcp" + "github.com/gogf/gf/v2/os/glog" ) func main() { @@ -14,7 +14,7 @@ func main() { p := gpool.New(3000*time.Millisecond, func() (interface{}, error) { return gtcp.NewConn("www.baidu.com:80") }, func(i interface{}) { - glog.Println("expired") + glog.Print("expired") i.(*gtcp.Conn).Close() }) conn, err := p.Get() diff --git a/.example/container/gqueue/gqueue.go b/.example/container/gqueue/gqueue.go index 85985128c..5a1474330 100644 --- a/.example/container/gqueue/gqueue.go +++ b/.example/container/gqueue/gqueue.go @@ -4,9 +4,9 @@ import ( "fmt" "time" - "github.com/gogf/gf/container/gqueue" - "github.com/gogf/gf/os/gtime" - "github.com/gogf/gf/os/gtimer" + "github.com/gogf/gf/v2/container/gqueue" + "github.com/gogf/gf/v2/os/gtime" + "github.com/gogf/gf/v2/os/gtimer" ) func main() { diff --git a/.example/container/gqueue/gqueue2.go b/.example/container/gqueue/gqueue2.go index ca8ec4fa2..6b5459c47 100644 --- a/.example/container/gqueue/gqueue2.go +++ b/.example/container/gqueue/gqueue2.go @@ -4,8 +4,8 @@ import ( "fmt" "time" - "github.com/gogf/gf/container/gqueue" - "github.com/gogf/gf/os/gtimer" + "github.com/gogf/gf/v2/container/gqueue" + "github.com/gogf/gf/v2/os/gtimer" ) func main() { diff --git a/.example/container/gqueue/gqueue3.go b/.example/container/gqueue/gqueue3.go index 9c30d0888..55c279a4c 100644 --- a/.example/container/gqueue/gqueue3.go +++ b/.example/container/gqueue/gqueue3.go @@ -4,9 +4,9 @@ import ( "fmt" "time" - "github.com/gogf/gf/container/gqueue" - "github.com/gogf/gf/os/gtime" - "github.com/gogf/gf/os/gtimer" + "github.com/gogf/gf/v2/container/gqueue" + "github.com/gogf/gf/v2/os/gtime" + "github.com/gogf/gf/v2/os/gtimer" ) func main() { diff --git a/.example/container/gring/gring.go b/.example/container/gring/gring.go index 6a15f42d6..871c4b9c2 100644 --- a/.example/container/gring/gring.go +++ b/.example/container/gring/gring.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/container/gring" + "github.com/gogf/gf/v2/container/gring" ) func main() { diff --git a/.example/container/gring/gring_josephus.go b/.example/container/gring/gring_josephus.go index 5aafd5b46..078c31b5e 100644 --- a/.example/container/gring/gring_josephus.go +++ b/.example/container/gring/gring_josephus.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/container/gring" + "github.com/gogf/gf/v2/container/gring" ) type Player struct { diff --git a/.example/container/gset/gset1.go b/.example/container/gset/gset1.go index b4c18a341..2033edf3c 100644 --- a/.example/container/gset/gset1.go +++ b/.example/container/gset/gset1.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/container/gset" + "github.com/gogf/gf/v2/container/gset" ) func main() { diff --git a/.example/container/gset/gset2.go b/.example/container/gset/gset2.go index 051c9204f..25fc11762 100644 --- a/.example/container/gset/gset2.go +++ b/.example/container/gset/gset2.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/container/gset" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/container/gset" + "github.com/gogf/gf/v2/frame/g" ) func main() { diff --git a/.example/container/gset/json_marshal.go b/.example/container/gset/json_marshal.go index 18f308caf..a554f1e3b 100644 --- a/.example/container/gset/json_marshal.go +++ b/.example/container/gset/json_marshal.go @@ -3,7 +3,7 @@ package main import ( "encoding/json" "fmt" - "github.com/gogf/gf/container/gset" + "github.com/gogf/gf/v2/container/gset" ) func main() { diff --git a/.example/container/gset/json_unmarshal.go b/.example/container/gset/json_unmarshal.go index 4e90ce823..a71208a31 100644 --- a/.example/container/gset/json_unmarshal.go +++ b/.example/container/gset/json_unmarshal.go @@ -3,7 +3,7 @@ package main import ( "encoding/json" "fmt" - "github.com/gogf/gf/container/gset" + "github.com/gogf/gf/v2/container/gset" ) func main() { diff --git a/.example/container/gtree/gtree_avltree.go b/.example/container/gtree/gtree_avltree.go index 9f55d4395..5814212ec 100644 --- a/.example/container/gtree/gtree_avltree.go +++ b/.example/container/gtree/gtree_avltree.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/container/gtree" - "github.com/gogf/gf/util/gutil" + "github.com/gogf/gf/v2/container/gtree" + "github.com/gogf/gf/v2/util/gutil" ) func main() { diff --git a/.example/container/gtree/gtree_btree.go b/.example/container/gtree/gtree_btree.go index 268068435..f1b04d66b 100644 --- a/.example/container/gtree/gtree_btree.go +++ b/.example/container/gtree/gtree_btree.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/container/gtree" + "github.com/gogf/gf/v2/container/gtree" ) func main() { diff --git a/.example/container/gtree/gtree_redblackmap.go b/.example/container/gtree/gtree_redblackmap.go index d1b7e8b2e..5689110a2 100644 --- a/.example/container/gtree/gtree_redblackmap.go +++ b/.example/container/gtree/gtree_redblackmap.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/container/gtree" - "github.com/gogf/gf/util/gutil" + "github.com/gogf/gf/v2/container/gtree" + "github.com/gogf/gf/v2/util/gutil" ) func main() { diff --git a/.example/container/gtree/gtree_redblacktree.go b/.example/container/gtree/gtree_redblacktree.go index 557478663..01bbafb69 100644 --- a/.example/container/gtree/gtree_redblacktree.go +++ b/.example/container/gtree/gtree_redblacktree.go @@ -1,7 +1,7 @@ package main import ( - "github.com/gogf/gf/container/gtree" + "github.com/gogf/gf/v2/container/gtree" ) func main() { diff --git a/.example/container/gtype/gtype_int.go b/.example/container/gtype/gtype_int.go index e44949b02..ba8307290 100644 --- a/.example/container/gtype/gtype_int.go +++ b/.example/container/gtype/gtype_int.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/container/gtype" + "github.com/gogf/gf/v2/container/gtype" ) func main() { diff --git a/.example/container/gtype/json_marshal.go b/.example/container/gtype/json_marshal.go index 80052d23f..e91e4d7d9 100644 --- a/.example/container/gtype/json_marshal.go +++ b/.example/container/gtype/json_marshal.go @@ -3,7 +3,7 @@ package main import ( "encoding/json" "fmt" - "github.com/gogf/gf/container/gtype" + "github.com/gogf/gf/v2/container/gtype" ) func main() { diff --git a/.example/container/gtype/json_unmarshal.go b/.example/container/gtype/json_unmarshal.go index 6b72cab08..d460cfc67 100644 --- a/.example/container/gtype/json_unmarshal.go +++ b/.example/container/gtype/json_unmarshal.go @@ -3,7 +3,7 @@ package main import ( "encoding/json" "fmt" - "github.com/gogf/gf/container/gtype" + "github.com/gogf/gf/v2/container/gtype" ) func main() { diff --git a/.example/container/gvar/json_marshal.go b/.example/container/gvar/json_marshal.go index c8479a1eb..fbbb01679 100644 --- a/.example/container/gvar/json_marshal.go +++ b/.example/container/gvar/json_marshal.go @@ -3,7 +3,7 @@ package main import ( "encoding/json" "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { diff --git a/.example/container/gvar/json_unmarshal.go b/.example/container/gvar/json_unmarshal.go index 31aa9843a..2e79601e7 100644 --- a/.example/container/gvar/json_unmarshal.go +++ b/.example/container/gvar/json_unmarshal.go @@ -3,7 +3,7 @@ package main import ( "encoding/json" "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { diff --git a/.example/container/gvar/var.go b/.example/container/gvar/var.go index fe688e674..7752eed11 100644 --- a/.example/container/gvar/var.go +++ b/.example/container/gvar/var.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { diff --git a/.example/database/gdb/driver/driver/driver.go b/.example/database/gdb/driver/driver/driver.go index 5fd86304d..9350832c1 100644 --- a/.example/database/gdb/driver/driver/driver.go +++ b/.example/database/gdb/driver/driver/driver.go @@ -1,15 +1,10 @@ -// Copyright GoFrame Author(https://goframe.org). 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 driver import ( + "context" "database/sql" - "github.com/gogf/gf/database/gdb" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/os/gtime" ) // MyDriver is a custom database driver, which is used for testing only. @@ -47,9 +42,9 @@ func (d *MyDriver) New(core *gdb.Core, node *gdb.ConfigNode) (gdb.DB, error) { // DoQuery commits the sql string and its arguments to underlying driver // through given link object and returns the execution result. -func (d *MyDriver) DoQuery(link gdb.Link, sql string, args ...interface{}) (rows *sql.Rows, err error) { +func (d *MyDriver) DoQuery(ctx context.Context, link gdb.Link, sql string, args ...interface{}) (rows *sql.Rows, err error) { tsMilli := gtime.TimestampMilli() - rows, err = d.DriverMysql.DoQuery(link, sql, args...) + rows, err = d.DriverMysql.DoQuery(ctx, link, sql, args...) link.Exec( "INSERT INTO `monitor`(`sql`,`cost`,`time`,`error`) VALUES(?,?,?,?)", gdb.FormatSqlWithArgs(sql, args), @@ -62,9 +57,9 @@ func (d *MyDriver) DoQuery(link gdb.Link, sql string, args ...interface{}) (rows // DoExec commits the query string and its arguments to underlying driver // through given link object and returns the execution result. -func (d *MyDriver) DoExec(link gdb.Link, sql string, args ...interface{}) (result sql.Result, err error) { +func (d *MyDriver) DoExec(ctx context.Context, link gdb.Link, sql string, args ...interface{}) (result sql.Result, err error) { tsMilli := gtime.TimestampMilli() - result, err = d.DriverMysql.DoExec(link, sql, args...) + result, err = d.DriverMysql.DoExec(ctx, link, sql, args...) link.Exec( "INSERT INTO `monitor`(`sql`,`cost`,`time`,`error`) VALUES(?,?,?,?)", gdb.FormatSqlWithArgs(sql, args), diff --git a/.example/database/gdb/mssql/gdb_all.go b/.example/database/gdb/mssql/gdb_all.go index da70660b5..396099c6a 100644 --- a/.example/database/gdb/mssql/gdb_all.go +++ b/.example/database/gdb/mssql/gdb_all.go @@ -2,22 +2,22 @@ package main import ( "fmt" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/os/gtime" - _ "github.com/denisenkom/go-mssqldb" - "github.com/gogf/gf/frame/g" + //_ "github.com/denisenkom/go-mssqldb" + "github.com/gogf/gf/v2/frame/g" ) func main() { type Table2 struct { Id string `orm:"id;pr" json:"id"` //ID - Createtime gtime.Time `orm:"createtime" json:"createtime"` //创建时间 - Updatetime gtime.Time `orm:"updatetime" json:"updatetime"` //更新时间 + CreateTime gtime.Time `orm:"createtime" json:"createtime"` //创建时间 + UpdateTime gtime.Time `orm:"updatetime" json:"updatetime"` //更新时间 } var table2 Table2 - err := g.DB().Table("table2").Where("id=?", 1).Struct(&table2) + err := g.DB().Model("table2").Where("id", 1).Scan(&table2) if err != nil { panic(err) } - fmt.Println(table2.Createtime) + fmt.Println(table2.CreateTime) } diff --git a/.example/database/gdb/mssql/gdb_sqlserver.go b/.example/database/gdb/mssql/gdb_sqlserver.go index 0b81c802f..1281f0e08 100644 --- a/.example/database/gdb/mssql/gdb_sqlserver.go +++ b/.example/database/gdb/mssql/gdb_sqlserver.go @@ -5,8 +5,8 @@ import ( "time" //_ "github.com/denisenkom/go-mssqldb" - "github.com/gogf/gf/database/gdb" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/frame/g" ) // 本文件用于gf框架的mssql数据库操作示例,不作为单元测试使用 diff --git a/.example/database/gdb/mysql/config.toml b/.example/database/gdb/mysql/config.toml index beea9dcb5..0ea384859 100644 --- a/.example/database/gdb/mysql/config.toml +++ b/.example/database/gdb/mysql/config.toml @@ -4,7 +4,7 @@ [database.logger] Level = "all" Stdout = true - CtxKeys = ["Trace-Id"] + CtxKeys = ["RequestId"] [database.default] link = "mysql:root:12345678@tcp(127.0.0.1:3306)/test" debug = true diff --git a/.example/database/gdb/mysql/config/gdb.go b/.example/database/gdb/mysql/config/gdb.go index 6fb30486b..3dcb15ddd 100644 --- a/.example/database/gdb/mysql/config/gdb.go +++ b/.example/database/gdb/mysql/config/gdb.go @@ -1,7 +1,8 @@ package main import ( - "github.com/gogf/gf/database/gdb" + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/os/gctx" "sync" "time" ) @@ -24,13 +25,16 @@ func init() { } func main() { - wg := sync.WaitGroup{} + var ( + wg = sync.WaitGroup{} + ctx = gctx.New() + ) for i := 0; i < 100000; i++ { wg.Add(1) go func() { defer wg.Done() time.Sleep(10 * time.Second) - db.Table("user").Where("id=1").All() + db.Ctx(ctx).Model("user").Where("id=1").All() }() } wg.Wait() diff --git a/.example/database/gdb/mysql/gdb_all.go b/.example/database/gdb/mysql/gdb_all.go index 74830ee48..38c5e3409 100644 --- a/.example/database/gdb/mysql/gdb_all.go +++ b/.example/database/gdb/mysql/gdb_all.go @@ -2,27 +2,23 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gctx" ) func main() { - db := g.DB() + var ( + db = g.DB() + ctx = gctx.New() + ) // 开启调试模式,以便于记录所有执行的SQL db.SetDebug(true) - r, e := db.GetAll("SELECT * from `user` where id in(?)", g.Slice{}) + r, e := db.Ctx(ctx).GetAll("SELECT * from `user` where id in(?)", g.Slice{}) if e != nil { fmt.Println(e) } if r != nil { fmt.Println(r) } - return - //r, e := db.Table("user").Where("id in(?)", g.Slice{}).All() - //if e != nil { - // fmt.Println(e) - //} - //if r != nil { - // fmt.Println(r.List()) - //} } diff --git a/.example/database/gdb/mysql/gdb_args_slice.go b/.example/database/gdb/mysql/gdb_args_slice.go index ceebe23d1..88496f345 100644 --- a/.example/database/gdb/mysql/gdb_args_slice.go +++ b/.example/database/gdb/mysql/gdb_args_slice.go @@ -1,13 +1,19 @@ package main import ( - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gctx" ) func main() { - db := g.DB() + var ( + db = g.DB() + ctx = gctx.New() + ) - db.Table("user").Where("nickname like ? and passport like ?", g.Slice{"T3", "t3"}).OrderBy("id asc").All() + db.Ctx(ctx).Model("user"). + Where("nickname like ? and passport like ?", g.Slice{"T3", "t3"}). + OrderAsc("id").All() conditions := g.Map{ "nickname like ?": "%T%", @@ -16,8 +22,8 @@ func main() { "create_time > ?": 0, "id in(?)": g.Slice{1, 2, 3}, } - db.Table("user").Where(conditions).OrderBy("id asc").All() + db.Ctx(ctx).Model("user").Where(conditions).OrderAsc("id").All() var params []interface{} - db.Table("user").Where("1=1", params).OrderBy("id asc").All() + db.Ctx(ctx).Model("user").Where("1=1", params).OrderAsc("id").All() } diff --git a/.example/database/gdb/mysql/gdb_batch_insert.go b/.example/database/gdb/mysql/gdb_batch_insert.go index 171bb9fb4..cdc2e7b36 100644 --- a/.example/database/gdb/mysql/gdb_batch_insert.go +++ b/.example/database/gdb/mysql/gdb_batch_insert.go @@ -2,11 +2,15 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gctx" ) func main() { - db := g.DB() + var ( + db = g.DB() + ctx = gctx.New() + ) db.SetDebug(true) list := make(g.List, 0) for i := 0; i < 100; i++ { @@ -14,7 +18,7 @@ func main() { "name": fmt.Sprintf(`name_%d`, i), }) } - r, e := db.Table("user").Data(list).Batch(2).Insert() + r, e := db.Ctx(ctx).Model("user").Data(list).Batch(2).Insert() if e != nil { panic(e) } diff --git a/.example/database/gdb/mysql/gdb_binary.go b/.example/database/gdb/mysql/gdb_binary.go index f3d234736..e0f0b4f6b 100644 --- a/.example/database/gdb/mysql/gdb_binary.go +++ b/.example/database/gdb/mysql/gdb_binary.go @@ -2,10 +2,11 @@ package main import ( "fmt" + "github.com/gogf/gf/v2/os/gctx" - "github.com/gogf/gf/crypto/gaes" - "github.com/gogf/gf/database/gdb" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/crypto/gaes" + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/frame/g" ) func main() { @@ -19,6 +20,9 @@ func main() { Role: "master", Charset: "utf8", }) + var ( + ctx = gctx.New() + ) db, err := gdb.New() if err != nil { panic(err) @@ -33,7 +37,7 @@ func main() { } // 写入 - r, err := db.Table("user").Data(g.Map{ + r, err := db.Ctx(ctx).Model("user").Data(g.Map{ "uid": 1, "name": encryptedName, }).Save() @@ -43,9 +47,9 @@ func main() { fmt.Println(r.RowsAffected()) // 查询 - one, err := db.Table("user").Where("name=?", encryptedName).One() + one, err := db.Ctx(ctx).Model("user").Where("name=?", encryptedName).One() if err != nil { fmt.Println(err) } - fmt.Println(one.ToMap()) + fmt.Println(one.Map()) } diff --git a/.example/database/gdb/mysql/gdb_bit.go b/.example/database/gdb/mysql/gdb_bit.go index b7da01292..f08133af1 100644 --- a/.example/database/gdb/mysql/gdb_bit.go +++ b/.example/database/gdb/mysql/gdb_bit.go @@ -2,19 +2,23 @@ package main import ( "fmt" + "github.com/gogf/gf/v2/os/gctx" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { - db := g.DB() + var ( + db = g.DB() + ctx = gctx.New() + ) db.SetDebug(true) - r, e := db.Table("test").All() + r, e := db.Ctx(ctx).Model("test").All() if e != nil { panic(e) } if r != nil { - fmt.Println(r.ToList()) + fmt.Println(r.List()) } } diff --git a/.example/database/gdb/mysql/gdb_cache.go b/.example/database/gdb/mysql/gdb_cache.go index cefc858da..35583865b 100644 --- a/.example/database/gdb/mysql/gdb_cache.go +++ b/.example/database/gdb/mysql/gdb_cache.go @@ -1,8 +1,9 @@ package main import ( - "github.com/gogf/gf/database/gdb" - "github.com/gogf/gf/util/gutil" + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/os/gctx" + "github.com/gogf/gf/v2/util/gutil" "time" ) @@ -17,6 +18,9 @@ func main() { Role: "master", Charset: "utf8", }) + var ( + ctx = gctx.New() + ) db, err := gdb.New() if err != nil { panic(err) @@ -27,7 +31,7 @@ func main() { // 执行2次查询并将查询结果缓存3秒,并可执行缓存名称(可选) for i := 0; i < 3; i++ { - r, _ := db.Table("user").Cache(3000*time.Second).Where("id=?", 1).One() + r, _ := db.Ctx(ctx).Model("user").Cache(3000*time.Second).Where("id=?", 1).One() gutil.Dump(r.Map()) } diff --git a/.example/database/gdb/mysql/gdb_complecated.go b/.example/database/gdb/mysql/gdb_complecated.go index 0f8a9906f..b8af08994 100644 --- a/.example/database/gdb/mysql/gdb_complecated.go +++ b/.example/database/gdb/mysql/gdb_complecated.go @@ -1,12 +1,12 @@ package main import ( - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { // error! - r, err := g.DB().Table("user").Where(g.Map{ + r, err := g.DB().Model("user").Where(g.Map{ "or": g.Map{ "nickname": "jim", "create_time > ": "2019-10-01", diff --git a/.example/database/gdb/mysql/gdb_config.go b/.example/database/gdb/mysql/gdb_config.go index cb88e2d89..9e0efa73d 100644 --- a/.example/database/gdb/mysql/gdb_config.go +++ b/.example/database/gdb/mysql/gdb_config.go @@ -3,11 +3,11 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { - if r, err := g.DB().Table("user").Where("uid=?", 1).One(); err == nil { + if r, err := g.DB().Model("user").Where("uid=?", 1).One(); err == nil { fmt.Println(r["uid"].Int()) fmt.Println(r["name"].String()) } else { diff --git a/.example/database/gdb/mysql/gdb_config2.go b/.example/database/gdb/mysql/gdb_config2.go index dfe80bc19..15120d2d0 100644 --- a/.example/database/gdb/mysql/gdb_config2.go +++ b/.example/database/gdb/mysql/gdb_config2.go @@ -3,12 +3,12 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { g.Config().SetFileName("config2.toml") - if r, err := g.DB().Table("user").Where("uid=?", 1).One(); err == nil { + if r, err := g.DB().Model("user").Where("uid=?", 1).One(); err == nil { fmt.Println(r["uid"].Int()) fmt.Println(r["name"].String()) } else { diff --git a/.example/database/gdb/mysql/gdb_config3.go b/.example/database/gdb/mysql/gdb_config3.go index 11a531d55..960c34a24 100644 --- a/.example/database/gdb/mysql/gdb_config3.go +++ b/.example/database/gdb/mysql/gdb_config3.go @@ -3,19 +3,19 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { g.Config().SetFileName("config3.toml") - if r, err := g.DB().Table("user").Where("uid=?", 1).One(); err == nil { + if r, err := g.DB().Model("user").Where("uid=?", 1).One(); err == nil { fmt.Println(r["uid"].Int()) fmt.Println(r["name"].String()) } else { fmt.Println(err) } - if r, err := g.DB("user").Table("user").Where("uid=?", 1).One(); err == nil { + if r, err := g.DB("user").Model("user").Where("uid=?", 1).One(); err == nil { fmt.Println(r["uid"].Int()) fmt.Println(r["name"].String()) } else { diff --git a/.example/database/gdb/mysql/gdb_ctx.go b/.example/database/gdb/mysql/gdb_ctx.go index c296b59ba..a27edc2f9 100644 --- a/.example/database/gdb/mysql/gdb_ctx.go +++ b/.example/database/gdb/mysql/gdb_ctx.go @@ -2,11 +2,11 @@ package main import ( "context" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { - ctx := context.WithValue(context.Background(), "Trace-Id", "123456789") + ctx := context.WithValue(context.Background(), "RequestId", "123456789") _, err := g.DB().Ctx(ctx).Query("SELECT 1") if err != nil { panic(err) diff --git a/.example/database/gdb/mysql/gdb_ctx_model.go b/.example/database/gdb/mysql/gdb_ctx_model.go index ba7b83c02..3d8796f9a 100644 --- a/.example/database/gdb/mysql/gdb_ctx_model.go +++ b/.example/database/gdb/mysql/gdb_ctx_model.go @@ -2,11 +2,11 @@ package main import ( "context" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { - ctx := context.WithValue(context.Background(), "Trace-Id", "123456789") + ctx := context.WithValue(context.Background(), "RequestId", "123456789") _, err := g.DB().Model("user").Ctx(ctx).All() if err != nil { panic(err) diff --git a/.example/database/gdb/mysql/gdb_datetime.go b/.example/database/gdb/mysql/gdb_datetime.go index 440e70f1f..317316ec3 100644 --- a/.example/database/gdb/mysql/gdb_datetime.go +++ b/.example/database/gdb/mysql/gdb_datetime.go @@ -2,23 +2,20 @@ package main import ( "fmt" + "github.com/gogf/gf/v2/os/gctx" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gtime" ) func main() { - db := g.Database() + var ( + db = g.DB() + ctx = gctx.New() + ) db.SetDebug(true) - //r, err := db.Table("user").Data("create_time", gtime.Now().String()).Insert() - //if err == nil { - // fmt.Println(r.LastInsertId()) - //} else { - // panic(err) - //} - - r, err := db.Table("user").Data(g.Map{ + r, err := db.Ctx(ctx).Model("user").Data(g.Map{ "name": "john", "create_time": gtime.Now().String(), }).Insert() diff --git a/.example/database/gdb/mysql/gdb_debug1.go b/.example/database/gdb/mysql/gdb_debug1.go index 9a3bc10e3..8eaa2e49d 100644 --- a/.example/database/gdb/mysql/gdb_debug1.go +++ b/.example/database/gdb/mysql/gdb_debug1.go @@ -1,9 +1,10 @@ package main import ( - "github.com/gogf/gf/database/gdb" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gctx" + "github.com/gogf/gf/v2/os/glog" ) func main() { @@ -17,6 +18,9 @@ func main() { Role: "master", Charset: "utf8", }) + var ( + ctx = gctx.New() + ) db, err := gdb.New() if err != nil { panic(err) @@ -27,11 +31,11 @@ func main() { // 执行3条SQL查询 for i := 1; i <= 3; i++ { - db.Table("user").Where("uid=?", i).One() + db.Ctx(ctx).Model("user").Where("uid=?", i).One() } // 构造一条错误查询 - db.Table("user").Where("no_such_field=?", "just_test").One() + db.Model("user").Where("no_such_field=?", "just_test").One() - db.Table("user").Data(g.Map{"name": "smith"}).Where("uid=?", 1).Save() + db.Ctx(ctx).Model("user").Data(g.Map{"name": "smith"}).Where("uid=?", 1).Save() } diff --git a/.example/database/gdb/mysql/gdb_debug2.go b/.example/database/gdb/mysql/gdb_debug2.go index 0ed29c2a7..0ab81ac21 100644 --- a/.example/database/gdb/mysql/gdb_debug2.go +++ b/.example/database/gdb/mysql/gdb_debug2.go @@ -1,18 +1,22 @@ package main import ( - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gctx" ) func main() { - db := g.DB() + var ( + db = g.DB() + ctx = gctx.New() + ) // 执行3条SQL查询 for i := 1; i <= 3; i++ { - db.Table("user").Where("id=?", i).One() + db.Ctx(ctx).Model("user").Where("id=?", i).One() } // 构造一条错误查询 - db.Table("user").Where("no_such_field=?", "just_test").One() + db.Ctx(ctx).Model("user").Where("no_such_field=?", "just_test").One() - db.Table("user").Data(g.Map{"name": "smith"}).Where("uid=?", 1).Save() + db.Ctx(ctx).Model("user").Data(g.Map{"name": "smith"}).Where("uid=?", 1).Save() } diff --git a/.example/database/gdb/mysql/gdb_distinct.go b/.example/database/gdb/mysql/gdb_distinct.go index 189422f6b..c043102e9 100644 --- a/.example/database/gdb/mysql/gdb_distinct.go +++ b/.example/database/gdb/mysql/gdb_distinct.go @@ -1,7 +1,7 @@ package main import ( - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { diff --git a/.example/database/gdb/mysql/gdb_insert.go b/.example/database/gdb/mysql/gdb_insert.go index ee345b370..a8a3f1bbd 100644 --- a/.example/database/gdb/mysql/gdb_insert.go +++ b/.example/database/gdb/mysql/gdb_insert.go @@ -2,23 +2,23 @@ package main import ( "fmt" - "github.com/gogf/gf/database/gdb" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/frame/g" ) func main() { //db := g.DB() gdb.AddDefaultConfigNode(gdb.ConfigNode{ - LinkInfo: "root:12345678@tcp(127.0.0.1:3306)/test?parseTime=true&loc=Local", - Type: "mysql", - Charset: "utf8", + Link: "root:12345678@tcp(127.0.0.1:3306)/test?parseTime=true&loc=Local", + Type: "mysql", + Charset: "utf8", }) db, _ := gdb.New() db.SetDebug(true) - r, e := db.Table("user").Data(g.Map{ + r, e := db.Model("user").Data(g.Map{ "create_at": "now()", }).Unscoped().Insert() if e != nil { diff --git a/.example/database/gdb/mysql/gdb_issue_278.go b/.example/database/gdb/mysql/gdb_issue_278.go index 2f18da921..4bcb82ffa 100644 --- a/.example/database/gdb/mysql/gdb_issue_278.go +++ b/.example/database/gdb/mysql/gdb_issue_278.go @@ -3,12 +3,12 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) var ( tableName = "orders" - dao = g.DB().Table(tableName).Safe() + dao = g.DB().Model(tableName).Safe() ) type OrderServiceEntity struct { diff --git a/.example/database/gdb/mysql/gdb_json_xml.go b/.example/database/gdb/mysql/gdb_json_xml.go index 7a273b884..ec986e321 100644 --- a/.example/database/gdb/mysql/gdb_json_xml.go +++ b/.example/database/gdb/mysql/gdb_json_xml.go @@ -2,10 +2,11 @@ package main import ( "fmt" + "github.com/gogf/gf/v2/encoding/gjson" + "github.com/gogf/gf/v2/os/gctx" - "github.com/gogf/gf/database/gdb" - "github.com/gogf/gf/encoding/gparser" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/frame/g" ) func main() { @@ -19,19 +20,22 @@ func main() { Role: "master", Charset: "utf8", }) - db := g.DB() - one, err := db.Table("user").Where("id=?", 1).One() + var ( + db = g.DB() + ctx = gctx.New() + ) + one, err := db.Ctx(ctx).Model("user").Where("id=?", 1).One() if err != nil { panic(err) } // 使用内置方法转换为json/xml - fmt.Println(one.ToJson()) - fmt.Println(one.ToXml()) + fmt.Println(one.Json()) + fmt.Println(one.Xml()) // 自定义方法方法转换为json/xml - jsonContent, _ := gparser.VarToJson(one.ToMap()) + jsonContent, _ := gjson.New(one.Map()).ToJson() fmt.Println(string(jsonContent)) - xmlContent, _ := gparser.VarToXml(one.ToMap()) + xmlContent, _ := gjson.New(one.Map()).ToJson() fmt.Println(string(xmlContent)) } diff --git a/.example/database/gdb/mysql/gdb_pool.go b/.example/database/gdb/mysql/gdb_pool.go index 0a435d618..1ef261186 100644 --- a/.example/database/gdb/mysql/gdb_pool.go +++ b/.example/database/gdb/mysql/gdb_pool.go @@ -1,20 +1,24 @@ package main import ( + "github.com/gogf/gf/v2/os/gctx" "time" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { - db := g.DB() + var ( + db = g.DB() + ctx = gctx.New() + ) // 开启调试模式,以便于记录所有执行的SQL db.SetDebug(true) for { for i := 0; i < 10; i++ { - go db.Table("user").All() + go db.Ctx(ctx).Model("user").All() } time.Sleep(time.Millisecond * 100) } diff --git a/.example/database/gdb/mysql/gdb_reconnect.go b/.example/database/gdb/mysql/gdb_reconnect.go index 18d53ef14..4ae644c99 100644 --- a/.example/database/gdb/mysql/gdb_reconnect.go +++ b/.example/database/gdb/mysql/gdb_reconnect.go @@ -2,15 +2,19 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gctx" "time" ) func main() { - db := g.DB() + var ( + db = g.DB() + ctx = gctx.New() + ) db.SetDebug(true) for { - r, err := db.Table("user").All() + r, err := db.Ctx(ctx).Model("user").All() fmt.Println(err) fmt.Println(r) time.Sleep(time.Second * 10) diff --git a/.example/database/gdb/mysql/gdb_struct.go b/.example/database/gdb/mysql/gdb_struct.go index 6aa5b8830..5c1f421c8 100644 --- a/.example/database/gdb/mysql/gdb_struct.go +++ b/.example/database/gdb/mysql/gdb_struct.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { @@ -17,7 +17,7 @@ func main() { } user := (*User)(nil) fmt.Println(user) - err := db.Table("test").Where("id=1").Struct(&user) + err := db.Model("test").Where("id=1").Scan(&user) fmt.Println(err) fmt.Println(user) } diff --git a/.example/database/gdb/mysql/gdb_tables.go b/.example/database/gdb/mysql/gdb_tables.go index 8dbf2d222..f179183c5 100644 --- a/.example/database/gdb/mysql/gdb_tables.go +++ b/.example/database/gdb/mysql/gdb_tables.go @@ -1,14 +1,18 @@ package main import ( - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gctx" ) func main() { - db := g.DB() + var ( + db = g.DB() + ctx = gctx.New() + ) db.SetDebug(true) - tables, err := db.Tables() + tables, err := db.Tables(ctx) if err != nil { panic(err) } diff --git a/.example/database/gdb/mysql/gdb_tables_fields.go b/.example/database/gdb/mysql/gdb_tables_fields.go index 3f5409b95..96dff35ba 100644 --- a/.example/database/gdb/mysql/gdb_tables_fields.go +++ b/.example/database/gdb/mysql/gdb_tables_fields.go @@ -1,21 +1,25 @@ package main import ( - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gctx" ) func main() { - db := g.DB() + var ( + db = g.DB() + ctx = gctx.New() + ) db.SetDebug(true) - tables, e := db.Tables() + tables, e := db.Tables(ctx) if e != nil { panic(e) } if tables != nil { g.Dump(tables) for _, table := range tables { - fields, err := db.TableFields(table) + fields, err := db.TableFields(ctx, table) if err != nil { panic(err) } diff --git a/.example/database/gdb/mysql/gdb_transaction.go b/.example/database/gdb/mysql/gdb_transaction.go index fe5642ca2..a181829f4 100644 --- a/.example/database/gdb/mysql/gdb_transaction.go +++ b/.example/database/gdb/mysql/gdb_transaction.go @@ -1,7 +1,7 @@ package main import ( - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { diff --git a/.example/database/gdb/mysql/gdb_transaction_closure.go b/.example/database/gdb/mysql/gdb_transaction_closure.go index aa05d48d4..9c39a7db0 100644 --- a/.example/database/gdb/mysql/gdb_transaction_closure.go +++ b/.example/database/gdb/mysql/gdb_transaction_closure.go @@ -1,26 +1,29 @@ package main import ( - "github.com/gogf/gf/database/gdb" - "github.com/gogf/gf/frame/g" + "context" + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gctx" ) func main() { var ( err error db = g.DB() + ctx = gctx.New() table = "user" ) - if err = db.Transaction(func(tx *gdb.TX) error { + if err = db.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error { // Nested transaction 1. - if err = tx.Transaction(func(tx *gdb.TX) error { + if err = tx.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error { _, err = tx.Model(table).Data(g.Map{"id": 1, "name": "john"}).Insert() return err }); err != nil { return err } // Nested transaction 2, panic. - if err = tx.Transaction(func(tx *gdb.TX) error { + if err = tx.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error { _, err = tx.Model(table).Data(g.Map{"id": 2, "name": "smith"}).Insert() // Create a panic that can make this transaction rollback automatically. panic("error") diff --git a/.example/database/gdb/mysql/gdb_transaction_savepoint.go b/.example/database/gdb/mysql/gdb_transaction_savepoint.go index e677f15ab..13eba5d0b 100644 --- a/.example/database/gdb/mysql/gdb_transaction_savepoint.go +++ b/.example/database/gdb/mysql/gdb_transaction_savepoint.go @@ -1,7 +1,7 @@ package main import ( - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { diff --git a/.example/database/gdb/mysql/gdb_update_field.go b/.example/database/gdb/mysql/gdb_update_field.go index c824f4176..e653469f0 100644 --- a/.example/database/gdb/mysql/gdb_update_field.go +++ b/.example/database/gdb/mysql/gdb_update_field.go @@ -3,16 +3,16 @@ package main import ( "database/sql" - "github.com/gogf/gf/os/gfile" + "github.com/gogf/gf/v2/os/gfile" - "github.com/gogf/gf/encoding/gjson" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/encoding/gjson" + "github.com/gogf/gf/v2/frame/g" ) func main() { db := g.DB() table := "medicine_clinics_upload_yinchuan" - list, err := db.Table(table).All() + list, err := db.Model(table).All() if err != nil && err != sql.ErrNoRows { panic(err) } diff --git a/.example/database/gdb/mysql/gdb_update_union.go b/.example/database/gdb/mysql/gdb_update_union.go index a0e14b7c0..edacbdbe7 100644 --- a/.example/database/gdb/mysql/gdb_update_union.go +++ b/.example/database/gdb/mysql/gdb_update_union.go @@ -3,13 +3,13 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { db := g.DB() db.SetDebug(true) - result, err := db.Table("pw_passageway m,pw_template t").Data("t.status", 99).Where("m.templateId=t.id AND m.status = 0").Update() + result, err := db.Model("pw_passageway m,pw_template t").Data("t.status", 99).Where("m.templateId=t.id AND m.status = 0").Update() if err != nil { panic(err) } diff --git a/.example/database/gdb/mysql/gdb_value.go b/.example/database/gdb/mysql/gdb_value.go index 3ba996e67..aace6c5b2 100644 --- a/.example/database/gdb/mysql/gdb_value.go +++ b/.example/database/gdb/mysql/gdb_value.go @@ -2,11 +2,11 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { - one, err := g.DB().Table("carlist c"). + one, err := g.Model("carlist c"). LeftJoin("cardetail d", "c.postid=d.carid"). Where("c.postid", "142039140032006"). Fields("c.*,d.*").One() diff --git a/.example/database/gdb/mysql/gdb_with_insert.go b/.example/database/gdb/mysql/gdb_with_insert.go index 669ab3ce6..79e8e3d86 100644 --- a/.example/database/gdb/mysql/gdb_with_insert.go +++ b/.example/database/gdb/mysql/gdb_with_insert.go @@ -1,10 +1,12 @@ package main import ( + "context" "fmt" - "github.com/gogf/gf/database/gdb" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/util/gmeta" + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gctx" + "github.com/gogf/gf/v2/util/gmeta" ) func main() { @@ -30,13 +32,13 @@ func main() { } db := g.DB() - db.Transaction(func(tx *gdb.TX) error { + err := db.Transaction(gctx.New(), func(ctx context.Context, tx *gdb.TX) error { for i := 1; i <= 5; i++ { // User. user := User{ Name: fmt.Sprintf(`name_%d`, i), } - lastInsertId, err := db.Model(user).Data(user).OmitEmpty().InsertAndGetId() + lastInsertId, err := db.Ctx(ctx).Model(user).Data(user).OmitEmpty().InsertAndGetId() if err != nil { return err } @@ -45,7 +47,7 @@ func main() { Uid: int(lastInsertId), Address: fmt.Sprintf(`address_%d`, lastInsertId), } - _, err = db.Model(userDetail).Data(userDetail).OmitEmpty().Insert() + _, err = db.Ctx(ctx).Model(userDetail).Data(userDetail).OmitEmpty().Insert() if err != nil { return err } @@ -55,7 +57,7 @@ func main() { Uid: int(lastInsertId), Score: j, } - _, err = db.Model(userScore).Data(userScore).OmitEmpty().Insert() + _, err = db.Ctx(ctx).Model(userScore).Data(userScore).OmitEmpty().Insert() if err != nil { return err } @@ -63,4 +65,5 @@ func main() { } return nil }) + fmt.Println(err) } diff --git a/.example/database/gdb/mysql/gdb_with_slect.go b/.example/database/gdb/mysql/gdb_with_slect.go index e15cf40f9..327062e88 100644 --- a/.example/database/gdb/mysql/gdb_with_slect.go +++ b/.example/database/gdb/mysql/gdb_with_slect.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/util/gmeta" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/util/gmeta" ) func main() { diff --git a/.example/database/gdb/mysql/issue364.go b/.example/database/gdb/mysql/issue364.go index cae5f6ace..2f84b1aaf 100644 --- a/.example/database/gdb/mysql/issue364.go +++ b/.example/database/gdb/mysql/issue364.go @@ -1,7 +1,7 @@ package main import ( - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" "time" ) @@ -9,7 +9,7 @@ func test1() { db := g.DB() db.SetDebug(true) time.Sleep(1 * time.Minute) - r, e := db.Table("test").Where("id", 10000).Count() + r, e := db.Model("test").Where("id", 10000).Count() if e != nil { panic(e) } @@ -19,7 +19,7 @@ func test1() { func test2() { db := g.DB() db.SetDebug(true) - dao := db.Table("test").Safe() + dao := db.Model("test").Safe() time.Sleep(1 * time.Minute) r, e := dao.Where("id", 10000).Count() if e != nil { diff --git a/.example/database/gdb/oracle/gdb.go b/.example/database/gdb/oracle/gdb.go index 902015a13..c2f35661d 100644 --- a/.example/database/gdb/oracle/gdb.go +++ b/.example/database/gdb/oracle/gdb.go @@ -5,8 +5,8 @@ import ( "time" //_ "github.com/mattn/go-oci8" - "github.com/gogf/gf/database/gdb" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/frame/g" ) // 本文件用于gf框架的mysql数据库操作示例,不作为单元测试使用 diff --git a/.example/database/gdb/sqlite/sqlite.go b/.example/database/gdb/sqlite/sqlite.go index 6224914ee..4160d5f4d 100644 --- a/.example/database/gdb/sqlite/sqlite.go +++ b/.example/database/gdb/sqlite/sqlite.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/database/gdb" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/frame/g" _ "github.com/mattn/go-sqlite3" ) diff --git a/.example/database/gredis/gredis.go b/.example/database/gredis/gredis.go index a276da6f9..32815d06c 100644 --- a/.example/database/gredis/gredis.go +++ b/.example/database/gredis/gredis.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/database/gredis" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/database/gredis" + "github.com/gogf/gf/v2/util/gconv" ) // 使用原生gredis.New操作redis,但是注意需要自己调用Close方法关闭redis链接池 diff --git a/.example/database/gredis/gredis2.go b/.example/database/gredis/gredis2.go index d4ef9aaeb..e141cb06e 100644 --- a/.example/database/gredis/gredis2.go +++ b/.example/database/gredis/gredis2.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/util/gconv" ) // 使用框架封装的g.Redis()方法获得redis操作对象单例,不需要开发者显示调用Close方法 diff --git a/.example/database/gredis/gredis_conn_do.go b/.example/database/gredis/gredis_conn_do.go index a87e993ba..6f3f2c6a2 100644 --- a/.example/database/gredis/gredis_conn_do.go +++ b/.example/database/gredis/gredis_conn_do.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/util/gconv" ) func main() { diff --git a/.example/database/gredis/gredis_conn_do_var.go b/.example/database/gredis/gredis_conn_do_var.go index c19c29cbc..363d762ed 100644 --- a/.example/database/gredis/gredis_conn_do_var.go +++ b/.example/database/gredis/gredis_conn_do_var.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { diff --git a/.example/database/gredis/gredis_conn_send.go b/.example/database/gredis/gredis_conn_send.go index a6d6156ac..727e38ffc 100644 --- a/.example/database/gredis/gredis_conn_send.go +++ b/.example/database/gredis/gredis_conn_send.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/util/gconv" ) func main() { diff --git a/.example/database/gredis/gredis_conn_send_var.go b/.example/database/gredis/gredis_conn_send_var.go index 5ad22b84e..019582ddd 100644 --- a/.example/database/gredis/gredis_conn_send_var.go +++ b/.example/database/gredis/gredis_conn_send_var.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { diff --git a/.example/database/gredis/gredis_conn_subscribe.go b/.example/database/gredis/gredis_conn_subscribe.go index 40a2e6955..7baf3a62d 100644 --- a/.example/database/gredis/gredis_conn_subscribe.go +++ b/.example/database/gredis/gredis_conn_subscribe.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/util/gconv" ) func main() { diff --git a/.example/database/gredis/gredis_conn_subscribe_var.go b/.example/database/gredis/gredis_conn_subscribe_var.go index bb8857cb7..d171d2cac 100644 --- a/.example/database/gredis/gredis_conn_subscribe_var.go +++ b/.example/database/gredis/gredis_conn_subscribe_var.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { diff --git a/.example/debug/gdebug/gdebug.go b/.example/debug/gdebug/gdebug.go index 2410096a9..2c67adf32 100644 --- a/.example/debug/gdebug/gdebug.go +++ b/.example/debug/gdebug/gdebug.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "github.com/gogf/gf/debug/gdebug" + "github.com/gogf/gf/v2/debug/gdebug" ) func main() { diff --git a/.example/debug/gdebug/gdebug_info.go b/.example/debug/gdebug/gdebug_info.go index 0e07ca12b..a829d8a7f 100644 --- a/.example/debug/gdebug/gdebug_info.go +++ b/.example/debug/gdebug/gdebug_info.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "github.com/gogf/gf/debug/gdebug" + "github.com/gogf/gf/v2/debug/gdebug" ) func main() { diff --git a/.example/encoding/gbase64/gbase64.go b/.example/encoding/gbase64/gbase64.go index ecf665407..e87206a9c 100644 --- a/.example/encoding/gbase64/gbase64.go +++ b/.example/encoding/gbase64/gbase64.go @@ -3,7 +3,7 @@ package gbase64 import ( "fmt" - "github.com/gogf/gf/encoding/gbase64" + "github.com/gogf/gf/v2/encoding/gbase64" ) func main() { diff --git a/.example/encoding/gbinary/binary.go b/.example/encoding/gbinary/binary.go index de2f5e1ec..53e1e81de 100644 --- a/.example/encoding/gbinary/binary.go +++ b/.example/encoding/gbinary/binary.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/encoding/gbinary" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/encoding/gbinary" + "github.com/gogf/gf/v2/os/glog" ) func main() { diff --git a/.example/encoding/gbinary/bits1.go b/.example/encoding/gbinary/bits1.go index 973e589bb..6d2696157 100644 --- a/.example/encoding/gbinary/bits1.go +++ b/.example/encoding/gbinary/bits1.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/encoding/gbinary" + "github.com/gogf/gf/v2/encoding/gbinary" ) func main() { diff --git a/.example/encoding/gbinary/bits2.go b/.example/encoding/gbinary/bits2.go index 0332cf362..d85d04cb8 100644 --- a/.example/encoding/gbinary/bits2.go +++ b/.example/encoding/gbinary/bits2.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/encoding/gbinary" + "github.com/gogf/gf/v2/encoding/gbinary" ) func main() { diff --git a/.example/encoding/gcfg/gcfg1.go b/.example/encoding/gcfg/gcfg1.go index a9414223e..b59e0af91 100644 --- a/.example/encoding/gcfg/gcfg1.go +++ b/.example/encoding/gcfg/gcfg1.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { diff --git a/.example/encoding/gcharset/gcharset.go b/.example/encoding/gcharset/gcharset.go index 07d2d37ec..cf3a8017a 100644 --- a/.example/encoding/gcharset/gcharset.go +++ b/.example/encoding/gcharset/gcharset.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/encoding/gcharset" + "github.com/gogf/gf/v2/encoding/gcharset" ) func main() { diff --git a/.example/encoding/gcompress/unzip.go b/.example/encoding/gcompress/unzip.go index 9f983fb3e..112b1977f 100644 --- a/.example/encoding/gcompress/unzip.go +++ b/.example/encoding/gcompress/unzip.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/encoding/gcompress" + "github.com/gogf/gf/v2/encoding/gcompress" ) func main() { diff --git a/.example/encoding/gcompress/unzip_content.go b/.example/encoding/gcompress/unzip_content.go index c6e25efed..b5d464998 100644 --- a/.example/encoding/gcompress/unzip_content.go +++ b/.example/encoding/gcompress/unzip_content.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/encoding/gcompress" - "github.com/gogf/gf/os/gfile" + "github.com/gogf/gf/v2/encoding/gcompress" + "github.com/gogf/gf/v2/os/gfile" ) func main() { diff --git a/.example/encoding/gcompress/zip.go b/.example/encoding/gcompress/zip.go index c827c1d4f..6e055200d 100644 --- a/.example/encoding/gcompress/zip.go +++ b/.example/encoding/gcompress/zip.go @@ -3,7 +3,7 @@ package main import ( "archive/zip" "fmt" - "github.com/gogf/gf/encoding/gcompress" + "github.com/gogf/gf/v2/encoding/gcompress" "io" "os" "path/filepath" diff --git a/.example/encoding/ghash/ghash_repeat_check.go b/.example/encoding/ghash/ghash_repeat_check.go index da613411c..8451b1bc6 100644 --- a/.example/encoding/ghash/ghash_repeat_check.go +++ b/.example/encoding/ghash/ghash_repeat_check.go @@ -4,7 +4,7 @@ import ( "fmt" "strconv" - "github.com/gogf/gf/encoding/ghash" + "github.com/gogf/gf/v2/encoding/ghash" ) func main() { diff --git a/.example/encoding/gini/gini.go b/.example/encoding/gini/gini.go index 758c5210b..9e6c55a58 100644 --- a/.example/encoding/gini/gini.go +++ b/.example/encoding/gini/gini.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "github.com/gogf/gf/encoding/gini" + "github.com/gogf/gf/v2/encoding/gini" ) func main() { diff --git a/.example/encoding/gjson/gjson.go b/.example/encoding/gjson/gjson.go index 5b2510930..07da40f89 100644 --- a/.example/encoding/gjson/gjson.go +++ b/.example/encoding/gjson/gjson.go @@ -3,9 +3,9 @@ package main import ( "fmt" - "github.com/gogf/gf/encoding/gjson" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/encoding/gjson" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gtime" ) func getByPattern() { diff --git a/.example/encoding/gjson/issue#IZXU2.go b/.example/encoding/gjson/issue#IZXU2.go index e96f428d3..abbbc7fd9 100644 --- a/.example/encoding/gjson/issue#IZXU2.go +++ b/.example/encoding/gjson/issue#IZXU2.go @@ -4,7 +4,7 @@ import ( "encoding/json" "fmt" - "github.com/gogf/gf/encoding/gjson" + "github.com/gogf/gf/v2/encoding/gjson" ) type XinYanModel struct { diff --git a/.example/encoding/gjson/issue283.go b/.example/encoding/gjson/issue283.go index 7e01a7926..52b20a274 100644 --- a/.example/encoding/gjson/issue283.go +++ b/.example/encoding/gjson/issue283.go @@ -1,9 +1,9 @@ package main import ( - "github.com/gogf/gf/encoding/gjson" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/encoding/gjson" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/glog" ) type GameUser struct { diff --git a/.example/encoding/gjson/issue360.go b/.example/encoding/gjson/issue360.go index dc0f9555c..7b753f312 100644 --- a/.example/encoding/gjson/issue360.go +++ b/.example/encoding/gjson/issue360.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "github.com/gogf/gf/encoding/gjson" + "github.com/gogf/gf/v2/encoding/gjson" ) func main() { diff --git a/.example/encoding/gparser/config.yaml b/.example/encoding/gparser/config.yaml deleted file mode 100644 index 7fe5f397a..000000000 --- a/.example/encoding/gparser/config.yaml +++ /dev/null @@ -1,44 +0,0 @@ - -broker: - ip: "127.0.0.1" - tcpport: "4222" - httpport: "8222" - user: "alfxnats" - pwd: "alfxnats" - clusterid: "alfxnats" -database: - ip: "110.1.1.227" - port: "27017" - user: "alfxdev" - pwd: "alfxdev" - dbname: "alfxdev" -scheduler: - a2rparallel: 4 - sleeptime: 300 -worker: - name: "worker1" - domains: - officenet: 3 - producnet: 3 - free: 3 - temppath: "/home/alfx/proc" -common: - filepath: "/home/alfx/file" - logpath: "home/alfx/log" - logdebug: true - logtrace: true -report: - localip: "127.0.0.1" - localport: "" - - - - - - - - - - - - diff --git a/.example/encoding/gparser/gparser.go b/.example/encoding/gparser/gparser.go deleted file mode 100644 index df42f1ffd..000000000 --- a/.example/encoding/gparser/gparser.go +++ /dev/null @@ -1,217 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/gogf/gf/encoding/gparser" - "github.com/gogf/gf/os/glog" -) - -func getWithPattern1() { - data := - `{ - "users" : { - "count" : 100, - "list" : [ - {"name" : "Ming", "score" : 60}, - {"name" : "John", "score" : 99.5} - ] - } - }` - - if p, e := gparser.LoadContent([]byte(data)); e != nil { - glog.Error(e) - } else { - fmt.Println("John Score:", p.GetFloat32("users.list.1.score")) - } -} - -func getWithPattern2() { - data := - ` - - Tove - Jani - Reminder - Don't forget me this weekend! - ` - - if p, e := gparser.LoadContent([]byte(data)); e != nil { - glog.Error(e) - } else { - fmt.Println("Heading:", p.GetString("note.heading")) - } -} - -// 当键名存在"."号时,检索优先级:键名->层级,因此不会引起歧义 -func multiDots1() { - data := - `{ - "users" : { - "count" : 100 - }, - "users.count" : 101 - }` - if p, e := gparser.LoadContent([]byte(data)); e != nil { - glog.Error(e) - } else { - fmt.Println("Users Count:", p.Get("users.count")) - } -} - -func multiDots2() { - data := - `{ - "users" : { - "count" : { - "type1" : 1, - "type2" : 2 - }, - "count.type1" : 100 - } - }` - if p, e := gparser.LoadContent([]byte(data)); e != nil { - glog.Error(e) - } else { - fmt.Println("Users Count:", p.Get("users.count.type1")) - fmt.Println("Users Count:", p.Get("users.count.type2")) - } -} - -// 设置数据 -func set1() { - data := - ` -
- 10 - gf article1gf content1 - gf article2gf content2 - gf article3gf content3 -
` - if p, e := gparser.LoadContent([]byte(data)); e != nil { - glog.Error(e) - } else { - p.Set("article.list.0", nil) - c, _ := p.ToJson() - fmt.Println(string(c)) - // {"article":{"count":"10","list":[{"content":"gf content2","title":"gf article2"},{"content":"gf content3","title":"gf article3"}]}} - } -} - -func set2() { - data := - `{ - "users" : { - "count" : 100 - } - }` - if p, e := gparser.LoadContent([]byte(data)); e != nil { - glog.Error(e) - } else { - p.Set("users.count", 1) - p.Set("users.list", []string{"John", "小明"}) - c, _ := p.ToJson() - fmt.Println(string(c)) - } -} - -func makeXml1() { - p := gparser.New(nil) - p.Set("name", "john") - p.Set("age", 18) - p.Set("scores", map[string]int{ - "语文": 100, - "数学": 100, - "英语": 100, - }) - c, _ := p.ToXmlIndent("simple-xml") - fmt.Println(string(c)) -} - -func makeJson1() { - type Order struct { - Id int `json:"id"` - Price float32 `json:"price"` - } - p := gparser.New(nil) - p.Set("orders.list.0", Order{1, 100}) - p.Set("orders.list.1", Order{2, 666}) - p.Set("orders.list.2", Order{3, 999.99}) - fmt.Println("Order 1 Price:", p.Get("orders.list.1.price")) - c, _ := p.ToJson() - fmt.Println(string(c)) -} - -func makeJson2() { - p := gparser.New(map[string]string{ - "k1": "v1", - "k2": "v2", - }) - p.Set("k1.1", []int{1, 2, 3}) - //p.Set("0.0.1", []int{1,2,3}) - c, _ := p.ToJson() - fmt.Println(string(c)) -} - -func makeJson3() { - p := gparser.New([]string{"a"}) - p.Set("0.0.0", []int{1, 2, 3}) - c, _ := p.ToJson() - fmt.Println(string(c)) -} - -func toStruct1() { - type Info struct { - Name string - Url string - } - o := Info{} - p := gparser.New(map[string]string{ - "Name": "gf", - "Url": "https://gitee.com/johng", - }) - p.ToStruct(&o) - fmt.Println("Name:", o.Name) - fmt.Println("Url :", o.Url) -} - -func convert() { - p := gparser.New(map[string]string{ - "name": "gf", - "site": "https://gitee.com/johng", - }) - c, _ := p.ToJson() - fmt.Println("JSON:") - fmt.Println(string(c)) - fmt.Println("======================") - - fmt.Println("XML:") - c, _ = p.ToXmlIndent() - fmt.Println(string(c)) - fmt.Println("======================") - - fmt.Println("YAML:") - c, _ = p.ToYaml() - fmt.Println(string(c)) - fmt.Println("======================") - - fmt.Println("TOML:") - c, _ = p.ToToml() - fmt.Println(string(c)) - -} - -func remove1() { - p := gparser.New(map[string]string{ - "k1": "v1", - "k2": "v2", - }) - p.Set("0.0.0.0.0.0.0.0", []int{1, 2, 3}) - p.Remove("0.0") - c, _ := p.ToJson() - fmt.Println(string(c)) -} - -func main() { - toStruct1() -} diff --git a/.example/encoding/gparser/gparser_xml.go b/.example/encoding/gparser/gparser_xml.go deleted file mode 100644 index 6d3ce48bb..000000000 --- a/.example/encoding/gparser/gparser_xml.go +++ /dev/null @@ -1,21 +0,0 @@ -package main - -import "github.com/gogf/gf/encoding/gparser" - -func main() { - xml := ` - - - 0 - 1 - 2 - 3 - - - ` - p, err := gparser.LoadContent([]byte(xml)) - if err != nil { - panic(err) - } - p.Dump() -} diff --git a/.example/encoding/gparser/gparser_yaml_issue336.go b/.example/encoding/gparser/gparser_yaml_issue336.go deleted file mode 100644 index ee796d16d..000000000 --- a/.example/encoding/gparser/gparser_yaml_issue336.go +++ /dev/null @@ -1,77 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/gogf/gf/encoding/gparser" -) - -type Conf struct { - Broker Broker - Database Database - Scheduler Scheduler - Worker Worker - Common Common - Report Report -} - -type Broker struct { - Ip string - Tcport string - Httpport string - User string - Pwd string - Clusterid string -} - -type Database struct { - Ip string - Port string - User string - Pwd string - Dbname string -} - -type Scheduler struct { - SleepTime int - Pidfilepath string - A2rparallel int -} - -type Worker struct { - Name string - Domains map[string]interface{} - Temppath string - Pidfilepath string -} - -type Common struct { - Filepath string - Logpath string - Logdebug bool - Logtrace bool -} - -type Report struct { - Localip string - Localport string //暂不启用 -} - -func main() { - _, err := gparser.Load("config.yaml") - if err != nil { - fmt.Println("oops,read config.yaml err:", err) - } - - //fmt.Println("yaml.v3读取yaml文件") - //f, err := os.Open("config.yaml") - //if err != nil { - // panic(err) - //} - //var conf Conf - //err = yaml.NewDecoder(f).Decode(&conf) - //if err != nil { - // panic(err) - //} - //fmt.Println(conf) -} diff --git a/.example/encoding/gyaml/gyaml.go b/.example/encoding/gyaml/gyaml.go index 20c4ae654..fc6380291 100644 --- a/.example/encoding/gyaml/gyaml.go +++ b/.example/encoding/gyaml/gyaml.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/encoding/gyaml" + "github.com/gogf/gf/v2/encoding/gyaml" ) func main() { diff --git a/.example/errors/gerror/gerror1.go b/.example/errors/gerror/gerror1.go index c644ae15d..32ed092e3 100644 --- a/.example/errors/gerror/gerror1.go +++ b/.example/errors/gerror/gerror1.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - "github.com/gogf/gf/errors/gerror" + "github.com/gogf/gf/v2/errors/gerror" ) func Error1() error { diff --git a/.example/errors/gerror/gerror2.go b/.example/errors/gerror/gerror2.go index 4ae5e3b3a..0d78edd99 100644 --- a/.example/errors/gerror/gerror2.go +++ b/.example/errors/gerror/gerror2.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/errors/gerror" + "github.com/gogf/gf/v2/errors/gerror" ) func OpenFile() error { diff --git a/.example/errors/gerror/gerror3.go b/.example/errors/gerror/gerror3.go index 30b67533f..007db4f0a 100644 --- a/.example/errors/gerror/gerror3.go +++ b/.example/errors/gerror/gerror3.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - "github.com/gogf/gf/errors/gerror" + "github.com/gogf/gf/v2/errors/gerror" ) func Error1() error { diff --git a/.example/errors/gerror/gerror4.go b/.example/errors/gerror/gerror4.go index da2200080..03a10ac2e 100644 --- a/.example/errors/gerror/gerror4.go +++ b/.example/errors/gerror/gerror4.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/errors/gerror" + "github.com/gogf/gf/v2/errors/gerror" ) func OpenFile() error { diff --git a/.example/errors/gerror/gerror5.go b/.example/errors/gerror/gerror5.go index 709b719a0..56426ae37 100644 --- a/.example/errors/gerror/gerror5.go +++ b/.example/errors/gerror/gerror5.go @@ -3,9 +3,9 @@ package main import ( "errors" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/os/glog" - "github.com/gogf/gf/errors/gerror" + "github.com/gogf/gf/v2/errors/gerror" ) func Error1() error { @@ -17,6 +17,6 @@ func Error2() error { } func main() { - glog.Println(Error1()) - glog.Println(Error2()) + glog.Print(Error1()) + glog.Print(Error2()) } diff --git a/.example/i18n/gi18n/gi18n-dir.go b/.example/i18n/gi18n/gi18n-dir.go index e9359c5ea..f05751e85 100644 --- a/.example/i18n/gi18n/gi18n-dir.go +++ b/.example/i18n/gi18n/gi18n-dir.go @@ -1,9 +1,10 @@ package main import ( + "context" "fmt" - "github.com/gogf/gf/i18n/gi18n" + "github.com/gogf/gf/v2/i18n/gi18n" ) func main() { @@ -13,6 +14,6 @@ func main() { if err != nil { panic(err) } - fmt.Println(t.Translate(`hello`)) - fmt.Println(t.Translate(`{#hello}{#world}!`)) + fmt.Println(t.Translate(context.TODO(), `hello`)) + fmt.Println(t.Translate(context.TODO(), `{#hello}{#world}!`)) } diff --git a/.example/i18n/gi18n/gi18n-file.go b/.example/i18n/gi18n/gi18n-file.go index 1a6d337c3..3c81bf1f5 100644 --- a/.example/i18n/gi18n/gi18n-file.go +++ b/.example/i18n/gi18n/gi18n-file.go @@ -1,9 +1,10 @@ package main import ( + "context" "fmt" - "github.com/gogf/gf/i18n/gi18n" + "github.com/gogf/gf/v2/i18n/gi18n" ) func main() { @@ -13,6 +14,6 @@ func main() { if err != nil { panic(err) } - fmt.Println(t.Translate(`hello`)) - fmt.Println(t.Translate(`{#hello}{#world}!`)) + fmt.Println(t.Translate(context.TODO(), `hello`)) + fmt.Println(t.Translate(context.TODO(), `{#hello}{#world}!`)) } diff --git a/.example/i18n/gi18n/gi18n.go b/.example/i18n/gi18n/gi18n.go index 630d5a954..e54764bbf 100644 --- a/.example/i18n/gi18n/gi18n.go +++ b/.example/i18n/gi18n/gi18n.go @@ -1,8 +1,10 @@ package main import ( + "context" "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/i18n/gi18n" ) func main() { @@ -10,6 +12,12 @@ func main() { orderId = 865271654 orderAmount = 99.8 ) - fmt.Println(g.I18n().Tfl(`en`, `{#OrderPaid}`, orderId, orderAmount)) - fmt.Println(g.I18n().Tfl(`zh-CN`, `{#OrderPaid}`, orderId, orderAmount)) + fmt.Println(g.I18n().Tf( + gi18n.WithLanguage(context.TODO(), `en`), + `{#OrderPaid}`, orderId, orderAmount, + )) + fmt.Println(g.I18n().Tf( + gi18n.WithLanguage(context.TODO(), `zh-CN`), + `{#OrderPaid}`, orderId, orderAmount, + )) } diff --git a/.example/i18n/gi18n/http_view_i18n.go b/.example/i18n/gi18n/http_view_i18n.go index ca5956c7b..e38340288 100644 --- a/.example/i18n/gi18n/http_view_i18n.go +++ b/.example/i18n/gi18n/http_view_i18n.go @@ -1,16 +1,20 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/i18n/gi18n" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { - g.I18n().SetPath("/Users/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/.example/i18n/gi18n/i18n") s := g.Server() - s.BindHandler("/", func(r *ghttp.Request) { - r.Response.WriteTplContent(`{#hello}{#world}!`, g.Map{ - "I18nLanguage": r.Get("lang", "zh-CN"), + s.Group("/", func(group *ghttp.RouterGroup) { + group.Middleware(func(r *ghttp.Request) { + r.SetCtx(gi18n.WithLanguage(r.Context(), r.GetString("lang", "zh-CN"))) + r.Middleware.Next() + }) + group.ALL("/", func(r *ghttp.Request) { + r.Response.WriteTplContent(`{#hello}{#world}!`) }) }) s.SetPort(8199) diff --git a/.example/i18n/gi18n/i18n/zh-CN.toml b/.example/i18n/gi18n/i18n/zh-CN.toml index 80acf06de..20406d93a 100644 --- a/.example/i18n/gi18n/i18n/zh-CN.toml +++ b/.example/i18n/gi18n/i18n/zh-CN.toml @@ -1 +1,3 @@ -OrderPaid = "您已成功完成订单号 #%d 支付,支付金额¥%.2f。" \ No newline at end of file +OrderPaid = "您已成功完成订单号 #%d 支付,支付金额¥%.2f。" +hello = "你好" +world = "世界" \ No newline at end of file diff --git a/.example/i18n/gi18n/resource/gi18n-resource.go b/.example/i18n/gi18n/resource/gi18n-resource.go index fa77596e0..7867b202c 100644 --- a/.example/i18n/gi18n/resource/gi18n-resource.go +++ b/.example/i18n/gi18n/resource/gi18n-resource.go @@ -3,9 +3,9 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" - _ "github.com/gogf/gf/os/gres/testdata" + _ "github.com/gogf/gf/v2/os/gres/testdata" ) func main() { diff --git a/.example/net/ghttp/client/cookie/client.go b/.example/net/ghttp/client/cookie/client.go index 68d659488..212a81f6b 100644 --- a/.example/net/ghttp/client/cookie/client.go +++ b/.example/net/ghttp/client/cookie/client.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/glog" ) func main() { diff --git a/.example/net/ghttp/client/cookie/server.go b/.example/net/ghttp/client/cookie/server.go index 9b021a700..e262d9097 100644 --- a/.example/net/ghttp/client/cookie/server.go +++ b/.example/net/ghttp/client/cookie/server.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/client/get.go b/.example/net/ghttp/client/get.go index 0d64792cc..623073f3d 100644 --- a/.example/net/ghttp/client/get.go +++ b/.example/net/ghttp/client/get.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/client/middleware/client.go b/.example/net/ghttp/client/middleware/client.go new file mode 100644 index 000000000..babba4fa5 --- /dev/null +++ b/.example/net/ghttp/client/middleware/client.go @@ -0,0 +1,64 @@ +package main + +import ( + "bytes" + "fmt" + "github.com/gogf/gf/v2/container/garray" + "github.com/gogf/gf/v2/crypto/gmd5" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/internal/json" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/gtime" + "github.com/gogf/gf/v2/util/gconv" + "github.com/gogf/gf/v2/util/guid" + "github.com/gogf/gf/v2/util/gutil" + "io/ioutil" + "net/http" +) + +const ( + appId = "123" + appSecret = "456" +) + +// 注入统一的接口签名参数 +func injectSignature(jsonContent []byte) []byte { + var m map[string]interface{} + _ = json.Unmarshal(jsonContent, &m) + if len(m) > 0 { + m["appid"] = appId + m["nonce"] = guid.S() + m["timestamp"] = gtime.Timestamp() + var ( + keyArray = garray.NewSortedStrArrayFrom(gutil.Keys(m)) + sigContent string + ) + keyArray.Iterator(func(k int, v string) bool { + sigContent += v + sigContent += gconv.String(m[v]) + return true + }) + m["signature"] = gmd5.MustEncryptString(gmd5.MustEncryptString(sigContent) + appSecret) + jsonContent, _ = json.Marshal(m) + } + return jsonContent +} + +func main() { + c := g.Client() + c.Use(func(c *ghttp.Client, r *http.Request) (resp *ghttp.ClientResponse, err error) { + bodyBytes, _ := ioutil.ReadAll(r.Body) + if len(bodyBytes) > 0 { + // 注入签名相关参数,修改Request原有的提交参数 + bodyBytes = injectSignature(bodyBytes) + r.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes)) + r.ContentLength = int64(len(bodyBytes)) + } + return c.Next(r) + }) + content := c.ContentJson().PostContent("http://127.0.0.1:8199/", g.Map{ + "name": "goframe", + "site": "https://goframe.org", + }) + fmt.Println(content) +} diff --git a/.example/net/ghttp/client/middleware/server.go b/.example/net/ghttp/client/middleware/server.go new file mode 100644 index 000000000..8b431f89b --- /dev/null +++ b/.example/net/ghttp/client/middleware/server.go @@ -0,0 +1,17 @@ +package main + +import ( + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" +) + +func main() { + s := g.Server() + s.Group("/", func(group *ghttp.RouterGroup) { + group.ALL("/", func(r *ghttp.Request) { + r.Response.Write(r.GetMap()) + }) + }) + s.SetPort(8199) + s.Run() +} diff --git a/.example/net/ghttp/client/upload-batch/client.go b/.example/net/ghttp/client/upload-batch/client.go index a0f6629f8..d8176b703 100644 --- a/.example/net/ghttp/client/upload-batch/client.go +++ b/.example/net/ghttp/client/upload-batch/client.go @@ -2,8 +2,8 @@ package main import ( "fmt" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/glog" ) func main() { diff --git a/.example/net/ghttp/client/upload-batch/client2.go b/.example/net/ghttp/client/upload-batch/client2.go index 24568e951..7cc2963e5 100644 --- a/.example/net/ghttp/client/upload-batch/client2.go +++ b/.example/net/ghttp/client/upload-batch/client2.go @@ -2,8 +2,8 @@ package main import ( "fmt" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/glog" ) func main() { diff --git a/.example/net/ghttp/client/upload-batch/server.go b/.example/net/ghttp/client/upload-batch/server.go index 482e1a7d6..5443dc298 100644 --- a/.example/net/ghttp/client/upload-batch/server.go +++ b/.example/net/ghttp/client/upload-batch/server.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) // Upload uploads files to /tmp . diff --git a/.example/net/ghttp/client/upload/client.go b/.example/net/ghttp/client/upload/client.go index a26548029..606c5252a 100644 --- a/.example/net/ghttp/client/upload/client.go +++ b/.example/net/ghttp/client/upload/client.go @@ -2,11 +2,11 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" "path/filepath" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/glog" ) func SendXmlFile(gameId int, areaName string, filePath string) error { diff --git a/.example/net/ghttp/client/upload/server.go b/.example/net/ghttp/client/upload/server.go index 26751703c..4573fae51 100644 --- a/.example/net/ghttp/client/upload/server.go +++ b/.example/net/ghttp/client/upload/server.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) // Upload uploads files to /tmp . diff --git a/.example/net/ghttp/server/admin/admin.go b/.example/net/ghttp/server/admin/admin.go index 5a7ffd87e..640954823 100644 --- a/.example/net/ghttp/server/admin/admin.go +++ b/.example/net/ghttp/server/admin/admin.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/body.go b/.example/net/ghttp/server/body.go index cb31dc20d..ea762fd54 100644 --- a/.example/net/ghttp/server/body.go +++ b/.example/net/ghttp/server/body.go @@ -2,8 +2,8 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" "io/ioutil" ) diff --git a/.example/net/ghttp/server/controller/user.go b/.example/net/ghttp/server/controller/user.go index 7b00b18b0..1fe010bbf 100644 --- a/.example/net/ghttp/server/controller/user.go +++ b/.example/net/ghttp/server/controller/user.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/frame/gmvc" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/frame/gmvc" ) type User struct { diff --git a/.example/net/ghttp/server/controller/view.go b/.example/net/ghttp/server/controller/view.go index 83302a526..70f3f96c3 100644 --- a/.example/net/ghttp/server/controller/view.go +++ b/.example/net/ghttp/server/controller/view.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/frame/gmvc" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/frame/gmvc" ) type Controller struct { diff --git a/.example/net/ghttp/server/cookie.go b/.example/net/ghttp/server/cookie.go index 6b424b228..7702456cb 100644 --- a/.example/net/ghttp/server/cookie.go +++ b/.example/net/ghttp/server/cookie.go @@ -1,9 +1,9 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/gtime" ) func main() { diff --git a/.example/net/ghttp/server/cors/cors1.go b/.example/net/ghttp/server/cors/cors1.go index afa7c9b8f..03c50b6aa 100644 --- a/.example/net/ghttp/server/cors/cors1.go +++ b/.example/net/ghttp/server/cors/cors1.go @@ -1,9 +1,9 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/glog" ) func MiddlewareCORS(r *ghttp.Request) { @@ -12,7 +12,7 @@ func MiddlewareCORS(r *ghttp.Request) { } func Order(r *ghttp.Request) { - glog.Println("order") + glog.Print("order") r.Response.Write("GET") } diff --git a/.example/net/ghttp/server/cors/cors2.go b/.example/net/ghttp/server/cors/cors2.go index f6b4b95ec..307ab1ddf 100644 --- a/.example/net/ghttp/server/cors/cors2.go +++ b/.example/net/ghttp/server/cors/cors2.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func MiddlewareCORS(r *ghttp.Request) { diff --git a/.example/net/ghttp/server/cors/cors3.go b/.example/net/ghttp/server/cors/cors3.go index f9e0e348e..499e75d28 100644 --- a/.example/net/ghttp/server/cors/cors3.go +++ b/.example/net/ghttp/server/cors/cors3.go @@ -3,8 +3,8 @@ package main import ( "net/http" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func MiddlewareCORS(r *ghttp.Request) { diff --git a/.example/net/ghttp/server/denyroutes/denyroutes.go b/.example/net/ghttp/server/denyroutes/denyroutes.go index 9e001a584..4dc0020f0 100644 --- a/.example/net/ghttp/server/denyroutes/denyroutes.go +++ b/.example/net/ghttp/server/denyroutes/denyroutes.go @@ -1,6 +1,6 @@ package main -import "github.com/gogf/gf/frame/g" +import "github.com/gogf/gf/v2/frame/g" func main() { s := g.Server() diff --git a/.example/net/ghttp/server/domain.go b/.example/net/ghttp/server/domain.go index db7b66f00..f43bc4611 100644 --- a/.example/net/ghttp/server/domain.go +++ b/.example/net/ghttp/server/domain.go @@ -1,6 +1,6 @@ package main -import "github.com/gogf/gf/net/ghttp" +import "github.com/gogf/gf/v2/net/ghttp" func Hello1(r *ghttp.Request) { r.Response.Write("127.0.0.1: Hello World1!") diff --git a/.example/net/ghttp/server/download/download.go b/.example/net/ghttp/server/download/download.go index c1cfba7d8..cc1ebee35 100644 --- a/.example/net/ghttp/server/download/download.go +++ b/.example/net/ghttp/server/download/download.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/duplicate/duplicate1.go b/.example/net/ghttp/server/duplicate/duplicate1.go index 6a16c77d4..65b506465 100644 --- a/.example/net/ghttp/server/duplicate/duplicate1.go +++ b/.example/net/ghttp/server/duplicate/duplicate1.go @@ -2,8 +2,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/duplicate/duplicate2.go b/.example/net/ghttp/server/duplicate/duplicate2.go index 89cafaaca..85bcae9a3 100644 --- a/.example/net/ghttp/server/duplicate/duplicate2.go +++ b/.example/net/ghttp/server/duplicate/duplicate2.go @@ -2,8 +2,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/frame/gmvc" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/frame/gmvc" ) type User struct { diff --git a/.example/net/ghttp/server/duplicate/duplicate3.go b/.example/net/ghttp/server/duplicate/duplicate3.go index 862c0601b..e2b870f6c 100644 --- a/.example/net/ghttp/server/duplicate/duplicate3.go +++ b/.example/net/ghttp/server/duplicate/duplicate3.go @@ -2,8 +2,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) type Object struct{} diff --git a/.example/net/ghttp/server/exit.go b/.example/net/ghttp/server/exit.go index 864a9ddec..c000f3270 100644 --- a/.example/net/ghttp/server/exit.go +++ b/.example/net/ghttp/server/exit.go @@ -1,9 +1,9 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/glog" ) func main() { @@ -16,10 +16,10 @@ func main() { }) s.BindHookHandlerByMap(p, map[string]ghttp.HandlerFunc{ ghttp.HookBeforeServe: func(r *ghttp.Request) { - glog.To(r.Response.Writer).Println("BeforeServe") + glog.To(r.Response.Writer).Print(r.Context(), "BeforeServe") }, ghttp.HookAfterServe: func(r *ghttp.Request) { - glog.To(r.Response.Writer).Println("AfterServe") + glog.To(r.Response.Writer).Print(r.Context(), "AfterServe") }, }) s.SetPort(8199) diff --git a/.example/net/ghttp/server/form/form-client.go b/.example/net/ghttp/server/form/form-client.go index 0ae72051c..9a7e29bce 100644 --- a/.example/net/ghttp/server/form/form-client.go +++ b/.example/net/ghttp/server/form/form-client.go @@ -1,7 +1,7 @@ package main import ( - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/form/form.go b/.example/net/ghttp/server/form/form.go index b12b99c75..447ea6d78 100644 --- a/.example/net/ghttp/server/form/form.go +++ b/.example/net/ghttp/server/form/form.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/hello.go b/.example/net/ghttp/server/hello.go index 4263a0e06..98bb79771 100644 --- a/.example/net/ghttp/server/hello.go +++ b/.example/net/ghttp/server/hello.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/hooks/cors1.go b/.example/net/ghttp/server/hooks/cors1.go index b4b1be33c..352bac573 100644 --- a/.example/net/ghttp/server/hooks/cors1.go +++ b/.example/net/ghttp/server/hooks/cors1.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func Order(r *ghttp.Request) { diff --git a/.example/net/ghttp/server/hooks/cors2.go b/.example/net/ghttp/server/hooks/cors2.go index 71e43e28a..dfa1d170b 100644 --- a/.example/net/ghttp/server/hooks/cors2.go +++ b/.example/net/ghttp/server/hooks/cors2.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func Order(r *ghttp.Request) { diff --git a/.example/net/ghttp/server/hooks/hooks1.go b/.example/net/ghttp/server/hooks/hooks1.go index c87922cf5..817a11eca 100644 --- a/.example/net/ghttp/server/hooks/hooks1.go +++ b/.example/net/ghttp/server/hooks/hooks1.go @@ -1,9 +1,9 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/glog" ) func main() { @@ -11,10 +11,10 @@ func main() { p := "/:name/info/{uid}" s := g.Server() s.BindHookHandlerByMap(p, map[string]ghttp.HandlerFunc{ - ghttp.HookBeforeServe: func(r *ghttp.Request) { glog.Println(ghttp.HookBeforeServe) }, - ghttp.HookAfterServe: func(r *ghttp.Request) { glog.Println(ghttp.HookAfterServe) }, - ghttp.HookBeforeOutput: func(r *ghttp.Request) { glog.Println(ghttp.HookBeforeOutput) }, - ghttp.HookAfterOutput: func(r *ghttp.Request) { glog.Println(ghttp.HookAfterOutput) }, + ghttp.HookBeforeServe: func(r *ghttp.Request) { glog.Print(ghttp.HookBeforeServe) }, + ghttp.HookAfterServe: func(r *ghttp.Request) { glog.Print(ghttp.HookAfterServe) }, + ghttp.HookBeforeOutput: func(r *ghttp.Request) { glog.Print(ghttp.HookBeforeOutput) }, + ghttp.HookAfterOutput: func(r *ghttp.Request) { glog.Print(ghttp.HookAfterOutput) }, }) s.BindHandler(p, func(r *ghttp.Request) { r.Response.Write("用户:", r.Get("name"), ", uid:", r.Get("uid")) diff --git a/.example/net/ghttp/server/hooks/hooks4.go b/.example/net/ghttp/server/hooks/hooks4.go index 3a44c8ae4..b13b8de69 100644 --- a/.example/net/ghttp/server/hooks/hooks4.go +++ b/.example/net/ghttp/server/hooks/hooks4.go @@ -2,8 +2,8 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/hooks/hooks5.go b/.example/net/ghttp/server/hooks/hooks5.go index d7af76007..c61a6b167 100644 --- a/.example/net/ghttp/server/hooks/hooks5.go +++ b/.example/net/ghttp/server/hooks/hooks5.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/hooks/hooks_param.go b/.example/net/ghttp/server/hooks/hooks_param.go index 6f6d698d7..2670e276a 100644 --- a/.example/net/ghttp/server/hooks/hooks_param.go +++ b/.example/net/ghttp/server/hooks/hooks_param.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/hooks/same_route_multi_hook.go b/.example/net/ghttp/server/hooks/same_route_multi_hook.go index 605b31a03..bd448bcb2 100644 --- a/.example/net/ghttp/server/hooks/same_route_multi_hook.go +++ b/.example/net/ghttp/server/hooks/same_route_multi_hook.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/https/https.go b/.example/net/ghttp/server/https/https.go index 3c2da3cec..5ccb9ab49 100644 --- a/.example/net/ghttp/server/https/https.go +++ b/.example/net/ghttp/server/https/https.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/https/https_http.go b/.example/net/ghttp/server/https/https_http.go index ad53a0fda..dc5c3ff0e 100644 --- a/.example/net/ghttp/server/https/https_http.go +++ b/.example/net/ghttp/server/https/https_http.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/log/log.go b/.example/net/ghttp/server/log/log.go index c4f1958d1..613a2c881 100644 --- a/.example/net/ghttp/server/log/log.go +++ b/.example/net/ghttp/server/log/log.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" "net/http" ) diff --git a/.example/net/ghttp/server/log/log_error.go b/.example/net/ghttp/server/log/log_error.go index 6b8bc48a4..727592f21 100644 --- a/.example/net/ghttp/server/log/log_error.go +++ b/.example/net/ghttp/server/log/log_error.go @@ -1,7 +1,7 @@ package main import ( - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/middleware/auth.go b/.example/net/ghttp/server/middleware/auth.go index cda744673..d4d4efdfd 100644 --- a/.example/net/ghttp/server/middleware/auth.go +++ b/.example/net/ghttp/server/middleware/auth.go @@ -3,8 +3,8 @@ package main import ( "net/http" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func MiddlewareAuth(r *ghttp.Request) { diff --git a/.example/net/ghttp/server/middleware/auth_exception.go b/.example/net/ghttp/server/middleware/auth_exception.go index f36bbe337..2dbfbcc4f 100644 --- a/.example/net/ghttp/server/middleware/auth_exception.go +++ b/.example/net/ghttp/server/middleware/auth_exception.go @@ -3,8 +3,8 @@ package main import ( "net/http" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func MiddlewareAuth(r *ghttp.Request) { diff --git a/.example/net/ghttp/server/middleware/cors.go b/.example/net/ghttp/server/middleware/cors.go index d7acaf51f..761d7f458 100644 --- a/.example/net/ghttp/server/middleware/cors.go +++ b/.example/net/ghttp/server/middleware/cors.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func MiddlewareCORS(r *ghttp.Request) { diff --git a/.example/net/ghttp/server/middleware/error_handling.go b/.example/net/ghttp/server/middleware/error_handling.go index afe4e98a3..9eee48fe3 100644 --- a/.example/net/ghttp/server/middleware/error_handling.go +++ b/.example/net/ghttp/server/middleware/error_handling.go @@ -3,8 +3,8 @@ package main import ( "net/http" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func MiddlewareAuth(r *ghttp.Request) { diff --git a/.example/net/ghttp/server/middleware/issue355.go b/.example/net/ghttp/server/middleware/issue355.go index 0470c4af4..048530a70 100644 --- a/.example/net/ghttp/server/middleware/issue355.go +++ b/.example/net/ghttp/server/middleware/issue355.go @@ -2,8 +2,8 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/middleware/log.go b/.example/net/ghttp/server/middleware/log.go index 225dc4c8c..09869d7ad 100644 --- a/.example/net/ghttp/server/middleware/log.go +++ b/.example/net/ghttp/server/middleware/log.go @@ -3,10 +3,10 @@ package main import ( "net/http" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/os/glog" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func MiddlewareAuth(r *ghttp.Request) { @@ -25,7 +25,7 @@ func MiddlewareCORS(r *ghttp.Request) { func MiddlewareLog(r *ghttp.Request) { r.Middleware.Next() - g.Log().Println(r.Response.Status, r.URL.Path) + g.Log().Print(r.Response.Status, r.URL.Path) } func main() { diff --git a/.example/net/ghttp/server/middleware/middleware.go b/.example/net/ghttp/server/middleware/middleware.go index 4dcf2ddb9..7ebad3f37 100644 --- a/.example/net/ghttp/server/middleware/middleware.go +++ b/.example/net/ghttp/server/middleware/middleware.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/middleware/param.go b/.example/net/ghttp/server/middleware/param.go index ece36b755..385db1d96 100644 --- a/.example/net/ghttp/server/middleware/param.go +++ b/.example/net/ghttp/server/middleware/param.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) // 前置中间件1 diff --git a/.example/net/ghttp/server/name.go b/.example/net/ghttp/server/name.go index 2e1cd60cc..fc5d5499b 100644 --- a/.example/net/ghttp/server/name.go +++ b/.example/net/ghttp/server/name.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) type User struct{} diff --git a/.example/net/ghttp/server/object/user.go b/.example/net/ghttp/server/object/user.go index 28d76456e..89215b840 100644 --- a/.example/net/ghttp/server/object/user.go +++ b/.example/net/ghttp/server/object/user.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) type User struct{} diff --git a/.example/net/ghttp/server/openapi/openapi.go b/.example/net/ghttp/server/openapi/openapi.go new file mode 100644 index 000000000..1cad75843 --- /dev/null +++ b/.example/net/ghttp/server/openapi/openapi.go @@ -0,0 +1,33 @@ +package main + +import ( + "context" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" +) + +type HelloReq struct { + g.Meta `path:"/hello" tags:"Test" method:"get" description:"Hello world handler for test"` + Content string `json:"content" in:"query"` +} + +type HelloRes struct { + Content string `json:"content" description:"Hello response content for test"` +} + +// Hello is an example handler. +func Hello(ctx context.Context, req *HelloReq) (res *HelloRes, err error) { + return &HelloRes{Content: req.Content}, nil +} + +func main() { + s := g.Server() + s.Use( + ghttp.MiddlewareHandlerResponse, + ) + s.BindHandler("/hello", Hello) + s.SetOpenApiPath("/api.json") + s.SetSwaggerPath("/swagger") + s.SetPort(8199) + s.Run() +} diff --git a/.example/net/ghttp/server/ports.go b/.example/net/ghttp/server/ports.go index fa6b8c883..dfb187c66 100644 --- a/.example/net/ghttp/server/ports.go +++ b/.example/net/ghttp/server/ports.go @@ -1,7 +1,7 @@ package main import ( - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/pprof.go b/.example/net/ghttp/server/pprof.go index 79f96ebdc..800f098f0 100644 --- a/.example/net/ghttp/server/pprof.go +++ b/.example/net/ghttp/server/pprof.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/redirect/back.go b/.example/net/ghttp/server/redirect/redirect_back.go similarity index 79% rename from .example/net/ghttp/server/redirect/back.go rename to .example/net/ghttp/server/redirect/redirect_back.go index ea26283e8..2e2f93e15 100644 --- a/.example/net/ghttp/server/redirect/back.go +++ b/.example/net/ghttp/server/redirect/redirect_back.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/redirect/redirect_to.go b/.example/net/ghttp/server/redirect/redirect_to.go new file mode 100644 index 000000000..b67b5a3c6 --- /dev/null +++ b/.example/net/ghttp/server/redirect/redirect_to.go @@ -0,0 +1,18 @@ +package main + +import ( + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" +) + +func main() { + s := g.Server() + s.BindHandler("/", func(r *ghttp.Request) { + r.Response.RedirectTo("/login") + }) + s.BindHandler("/login", func(r *ghttp.Request) { + r.Response.Writeln("Login First") + }) + s.SetPort(8199) + s.Run() +} diff --git a/.example/net/ghttp/server/reload/admin.go b/.example/net/ghttp/server/reload/admin.go index a4147ccc8..eff842a5a 100644 --- a/.example/net/ghttp/server/reload/admin.go +++ b/.example/net/ghttp/server/reload/admin.go @@ -1,7 +1,7 @@ package main import ( - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { diff --git a/.example/net/ghttp/server/reload/https.go b/.example/net/ghttp/server/reload/https.go index fa0a50cfd..ace087ee6 100644 --- a/.example/net/ghttp/server/reload/https.go +++ b/.example/net/ghttp/server/reload/https.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/reload/https_http.go b/.example/net/ghttp/server/reload/https_http.go index 155c53722..b0e8de1e8 100644 --- a/.example/net/ghttp/server/reload/https_http.go +++ b/.example/net/ghttp/server/reload/https_http.go @@ -1,7 +1,7 @@ package main import ( - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/reload/multi_port_and_server.go b/.example/net/ghttp/server/reload/multi_port_and_server.go index f599d0d4d..e6c4b5233 100644 --- a/.example/net/ghttp/server/reload/multi_port_and_server.go +++ b/.example/net/ghttp/server/reload/multi_port_and_server.go @@ -1,7 +1,7 @@ package main import ( - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { diff --git a/.example/net/ghttp/server/reload/simple.go b/.example/net/ghttp/server/reload/simple.go index 056ddd2eb..a5b06250b 100644 --- a/.example/net/ghttp/server/reload/simple.go +++ b/.example/net/ghttp/server/reload/simple.go @@ -3,9 +3,9 @@ package main import ( "time" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/os/gproc" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/gproc" ) func main() { diff --git a/.example/net/ghttp/server/request/basic.go b/.example/net/ghttp/server/request/basic.go index d706b6267..3c4aedf28 100644 --- a/.example/net/ghttp/server/request/basic.go +++ b/.example/net/ghttp/server/request/basic.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/request/exit/exit.go b/.example/net/ghttp/server/request/exit/exit.go index 8c4d96188..57d43e0d2 100644 --- a/.example/net/ghttp/server/request/exit/exit.go +++ b/.example/net/ghttp/server/request/exit/exit.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/request/json-xml/test1.go b/.example/net/ghttp/server/request/json-xml/test1.go index ace00f388..aabe06e5a 100644 --- a/.example/net/ghttp/server/request/json-xml/test1.go +++ b/.example/net/ghttp/server/request/json-xml/test1.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/request/json-xml/test2.go b/.example/net/ghttp/server/request/json-xml/test2.go index 5e3aed050..21b8de109 100644 --- a/.example/net/ghttp/server/request/json-xml/test2.go +++ b/.example/net/ghttp/server/request/json-xml/test2.go @@ -1,9 +1,9 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/util/gvalid" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/util/gvalid" ) type RegisterReq struct { @@ -25,7 +25,7 @@ func main() { //fmt.Println(r.GetBody()) if err := r.Parse(&req); err != nil { // Validation error. - if v, ok := err.(*gvalid.Error); ok { + if v, ok := err.(gvalid.Error); ok { r.Response.WriteJsonExit(RegisterRes{ Code: 1, Error: v.FirstString(), diff --git a/.example/net/ghttp/server/request/params/array.go b/.example/net/ghttp/server/request/params/array.go index ab177bffe..36ba6055f 100644 --- a/.example/net/ghttp/server/request/params/array.go +++ b/.example/net/ghttp/server/request/params/array.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/request/params/map.go b/.example/net/ghttp/server/request/params/map.go index 476c665a9..bc913ae33 100644 --- a/.example/net/ghttp/server/request/params/map.go +++ b/.example/net/ghttp/server/request/params/map.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/request/params/repeat.go b/.example/net/ghttp/server/request/params/repeat.go index 1384ac333..ba8f18e63 100644 --- a/.example/net/ghttp/server/request/params/repeat.go +++ b/.example/net/ghttp/server/request/params/repeat.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/request/priority.go b/.example/net/ghttp/server/request/priority.go index 538c77630..93ced6777 100644 --- a/.example/net/ghttp/server/request/priority.go +++ b/.example/net/ghttp/server/request/priority.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/request/request_struct.go b/.example/net/ghttp/server/request/request_struct.go index c2737f6ec..dfc15e349 100644 --- a/.example/net/ghttp/server/request/request_struct.go +++ b/.example/net/ghttp/server/request/request_struct.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/request/request_validation.go b/.example/net/ghttp/server/request/request_validation.go index fa23190b2..a6ab6185f 100644 --- a/.example/net/ghttp/server/request/request_validation.go +++ b/.example/net/ghttp/server/request/request_validation.go @@ -1,9 +1,9 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/util/gvalid" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/util/gvalid" ) type User struct { @@ -18,13 +18,13 @@ func main() { s.Group("/", func(rgroup *ghttp.RouterGroup) { rgroup.ALL("/user", func(r *ghttp.Request) { user := new(User) - if err := r.GetToStruct(user); err != nil { + if err := r.GetStruct(user); err != nil { r.Response.WriteJsonExit(g.Map{ "message": err, "errcode": 1, }) } - if err := gvalid.CheckStruct(user, nil); err != nil { + if err := gvalid.CheckStruct(r.Context(), user, nil); err != nil { r.Response.WriteJsonExit(g.Map{ "message": err.Maps(), "errcode": 1, diff --git a/.example/net/ghttp/server/request/struct/parse1.go b/.example/net/ghttp/server/request/struct/parse1.go index 4018bfa97..f00d79c81 100644 --- a/.example/net/ghttp/server/request/struct/parse1.go +++ b/.example/net/ghttp/server/request/struct/parse1.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/request/struct/parse2.go b/.example/net/ghttp/server/request/struct/parse2.go index fa72da655..8d5f19786 100644 --- a/.example/net/ghttp/server/request/struct/parse2.go +++ b/.example/net/ghttp/server/request/struct/parse2.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) type RegisterReq struct { diff --git a/.example/net/ghttp/server/request/validation/validation1.go b/.example/net/ghttp/server/request/validation/validation1/validation1.go similarity index 92% rename from .example/net/ghttp/server/request/validation/validation1.go rename to .example/net/ghttp/server/request/validation/validation1/validation1.go index 51a3c8346..759115fa1 100644 --- a/.example/net/ghttp/server/request/validation/validation1.go +++ b/.example/net/ghttp/server/request/validation/validation1/validation1.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) type RegisterReq struct { diff --git a/.example/net/ghttp/server/request/validation/validation2.go b/.example/net/ghttp/server/request/validation/validation2/validation2.go similarity index 86% rename from .example/net/ghttp/server/request/validation/validation2.go rename to .example/net/ghttp/server/request/validation/validation2/validation2.go index ccee1e3f9..93f5d021f 100644 --- a/.example/net/ghttp/server/request/validation/validation2.go +++ b/.example/net/ghttp/server/request/validation/validation2/validation2.go @@ -1,9 +1,9 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/util/gvalid" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/util/gvalid" ) type RegisterReq struct { @@ -24,7 +24,7 @@ func main() { var req *RegisterReq if err := r.Parse(&req); err != nil { // Validation error. - if v, ok := err.(*gvalid.Error); ok { + if v, ok := err.(gvalid.Error); ok { r.Response.WriteJsonExit(RegisterRes{ Code: 1, Error: v.FirstString(), diff --git a/.example/net/ghttp/server/resource/resource.go b/.example/net/ghttp/server/resource/resource.go index c9784aeed..c5b63fec9 100644 --- a/.example/net/ghttp/server/resource/resource.go +++ b/.example/net/ghttp/server/resource/resource.go @@ -3,10 +3,10 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/os/gres" - _ "github.com/gogf/gf/os/gres/testdata/data" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/gres" + _ "github.com/gogf/gf/v2/os/gres/testdata/data" ) func main() { diff --git a/.example/net/ghttp/server/reuseport/reuseport.go b/.example/net/ghttp/server/reuseport/reuseport.go index fe6522da6..a3d3764fa 100644 --- a/.example/net/ghttp/server/reuseport/reuseport.go +++ b/.example/net/ghttp/server/reuseport/reuseport.go @@ -1,16 +1,16 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/glog" ) func main() { s1 := ghttp.GetServer("s1") s1.SetPort(8882) s1.BindHandler("/", func(r *ghttp.Request) { - glog.Println("s1") + glog.Print(r.Context(), "s1") r.Response.Writeln("s1") }) s1.Start() @@ -18,7 +18,7 @@ func main() { s2 := ghttp.GetServer("s2") s2.SetPort(8882) s2.BindHandler("/", func(r *ghttp.Request) { - glog.Println("s2") + glog.Print(r.Context(), "s2") r.Response.Writeln("s2") }) s2.Start() diff --git a/.example/net/ghttp/server/router/duplicated/duplicated.go b/.example/net/ghttp/server/router/duplicated/duplicated.go index 9402a2a4d..fb23d03a2 100644 --- a/.example/net/ghttp/server/router/duplicated/duplicated.go +++ b/.example/net/ghttp/server/router/duplicated/duplicated.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/router/group/basic.go b/.example/net/ghttp/server/router/group/basic.go index 899b9243e..bd87d6867 100644 --- a/.example/net/ghttp/server/router/group/basic.go +++ b/.example/net/ghttp/server/router/group/basic.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/router/group/batch.go b/.example/net/ghttp/server/router/group/batch.go index 84519907b..185393e7f 100644 --- a/.example/net/ghttp/server/router/group/batch.go +++ b/.example/net/ghttp/server/router/group/batch.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) type Object struct{} diff --git a/.example/net/ghttp/server/router/group/level.go b/.example/net/ghttp/server/router/group/level.go index 1ee710586..f0563e671 100644 --- a/.example/net/ghttp/server/router/group/level.go +++ b/.example/net/ghttp/server/router/group/level.go @@ -3,8 +3,8 @@ package main import ( "net/http" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func MiddlewareAuth(r *ghttp.Request) { @@ -23,7 +23,7 @@ func MiddlewareCORS(r *ghttp.Request) { func MiddlewareLog(r *ghttp.Request) { r.Middleware.Next() - g.Log().Println(r.Response.Status, r.URL.Path) + g.Log().Print(r.Response.Status, r.URL.Path) } func main() { diff --git a/.example/net/ghttp/server/router/router1.go b/.example/net/ghttp/server/router/router1.go index 216e805cd..ce2276266 100644 --- a/.example/net/ghttp/server/router/router1.go +++ b/.example/net/ghttp/server/router/router1.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/router/router2.go b/.example/net/ghttp/server/router/router2.go index 285817740..3732e8026 100644 --- a/.example/net/ghttp/server/router/router2.go +++ b/.example/net/ghttp/server/router/router2.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/router/router3.go b/.example/net/ghttp/server/router/router3.go index 649694de2..dbf6ba73d 100644 --- a/.example/net/ghttp/server/router/router3.go +++ b/.example/net/ghttp/server/router/router3.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/router/router4.go b/.example/net/ghttp/server/router/router4.go index daa4b9f73..3218be3ea 100644 --- a/.example/net/ghttp/server/router/router4.go +++ b/.example/net/ghttp/server/router/router4.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/router/router5.go b/.example/net/ghttp/server/router/router5.go index c280fadb0..06664e3b5 100644 --- a/.example/net/ghttp/server/router/router5.go +++ b/.example/net/ghttp/server/router/router5.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/router/router6.go b/.example/net/ghttp/server/router/router6.go index d22002beb..548acfc5e 100644 --- a/.example/net/ghttp/server/router/router6.go +++ b/.example/net/ghttp/server/router/router6.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) // 试试模糊匹配规则不带名称会怎么样 diff --git a/.example/net/ghttp/server/servefile/servefile.go b/.example/net/ghttp/server/servefile/servefile.go new file mode 100644 index 000000000..85d52b650 --- /dev/null +++ b/.example/net/ghttp/server/servefile/servefile.go @@ -0,0 +1,15 @@ +package main + +import ( + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" +) + +func main() { + s := g.Server() + s.BindHandler("/", func(r *ghttp.Request) { + r.Response.ServeFile("test.txt") + }) + s.SetPort(8999) + s.Run() +} diff --git a/.example/net/ghttp/server/servefile/servefiledownload.go b/.example/net/ghttp/server/servefile/servefiledownload.go new file mode 100644 index 000000000..9c9f67ff5 --- /dev/null +++ b/.example/net/ghttp/server/servefile/servefiledownload.go @@ -0,0 +1,15 @@ +package main + +import ( + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" +) + +func main() { + s := g.Server() + s.BindHandler("/", func(r *ghttp.Request) { + r.Response.ServeFileDownload("test.txt") + }) + s.SetPort(8999) + s.Run() +} diff --git a/.example/net/ghttp/server/servefile/test.txt b/.example/net/ghttp/server/servefile/test.txt new file mode 100644 index 000000000..30d74d258 --- /dev/null +++ b/.example/net/ghttp/server/servefile/test.txt @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/.example/net/ghttp/server/server2.go b/.example/net/ghttp/server/server2.go index 800dd71f8..fe96ae6bb 100644 --- a/.example/net/ghttp/server/server2.go +++ b/.example/net/ghttp/server/server2.go @@ -1,7 +1,7 @@ package main import ( - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/session.go b/.example/net/ghttp/server/session.go index fd553cff9..704bc8a6d 100644 --- a/.example/net/ghttp/server/session.go +++ b/.example/net/ghttp/server/session.go @@ -1,9 +1,9 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/util/gconv" ) func main() { diff --git a/.example/net/ghttp/server/session/basic/session.go b/.example/net/ghttp/server/session/basic/session.go index c7a21a684..b2d101845 100644 --- a/.example/net/ghttp/server/session/basic/session.go +++ b/.example/net/ghttp/server/session/basic/session.go @@ -1,9 +1,9 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/gtime" ) func main() { diff --git a/.example/net/ghttp/server/session/redis/redis.go b/.example/net/ghttp/server/session/redis/redis.go index 5544c3318..f581dcdcd 100644 --- a/.example/net/ghttp/server/session/redis/redis.go +++ b/.example/net/ghttp/server/session/redis/redis.go @@ -1,10 +1,10 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/os/gsession" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/gsession" + "github.com/gogf/gf/v2/os/gtime" "time" ) diff --git a/.example/net/ghttp/server/session/redis/redis_bigint.go b/.example/net/ghttp/server/session/redis/redis_bigint.go new file mode 100644 index 000000000..07580bbfd --- /dev/null +++ b/.example/net/ghttp/server/session/redis/redis_bigint.go @@ -0,0 +1,36 @@ +package main + +import ( + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/gsession" +) + +func main() { + type User struct { + Id int64 + Name string + } + s := g.Server() + s.SetSessionStorage(gsession.NewStorageRedis(g.Redis())) + s.Group("/", func(group *ghttp.RouterGroup) { + group.GET("/set", func(r *ghttp.Request) { + user := &User{ + Id: 1265476890672672808, + Name: "john", + } + if err := r.Session.Set("user", user); err != nil { + panic(err) + } + r.Response.Write("ok") + }) + group.GET("/get", func(r *ghttp.Request) { + r.Response.WriteJson(r.Session.Get("user")) + }) + group.GET("/clear", func(r *ghttp.Request) { + r.Session.Clear() + }) + }) + s.SetPort(8199) + s.Run() +} diff --git a/.example/net/ghttp/server/static/static.go b/.example/net/ghttp/server/static/static.go index 3fbc63809..2a06b196d 100644 --- a/.example/net/ghttp/server/static/static.go +++ b/.example/net/ghttp/server/static/static.go @@ -1,6 +1,6 @@ package main -import "github.com/gogf/gf/frame/g" +import "github.com/gogf/gf/v2/frame/g" // 静态文件服务器基本使用 func main() { diff --git a/.example/net/ghttp/server/static/static_path.go b/.example/net/ghttp/server/static/static_path.go index 222c6be87..30579ec53 100644 --- a/.example/net/ghttp/server/static/static_path.go +++ b/.example/net/ghttp/server/static/static_path.go @@ -1,6 +1,6 @@ package main -import "github.com/gogf/gf/frame/g" +import "github.com/gogf/gf/v2/frame/g" // 静态文件服务器,支持自定义静态目录映射 func main() { diff --git a/.example/net/ghttp/server/static/static_path2.go b/.example/net/ghttp/server/static/static_path2.go index f626c99d5..30c5c3258 100644 --- a/.example/net/ghttp/server/static/static_path2.go +++ b/.example/net/ghttp/server/static/static_path2.go @@ -1,6 +1,6 @@ package main -import "github.com/gogf/gf/frame/g" +import "github.com/gogf/gf/v2/frame/g" // 静态文件服务器,支持自定义静态目录映射 func main() { diff --git a/.example/net/ghttp/server/status.go b/.example/net/ghttp/server/status.go index 34256f0c5..c06feca06 100644 --- a/.example/net/ghttp/server/status.go +++ b/.example/net/ghttp/server/status.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/status_map.go b/.example/net/ghttp/server/status_map.go index de0f8b1ca..517af3fc8 100644 --- a/.example/net/ghttp/server/status_map.go +++ b/.example/net/ghttp/server/status_map.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/status_redirect.go b/.example/net/ghttp/server/status_redirect.go index e525151a3..5658a3109 100644 --- a/.example/net/ghttp/server/status_redirect.go +++ b/.example/net/ghttp/server/status_redirect.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/template/build-in/objects/objects.go b/.example/net/ghttp/server/template/build-in/objects/objects.go index 2559da767..69d1311e5 100644 --- a/.example/net/ghttp/server/template/build-in/objects/objects.go +++ b/.example/net/ghttp/server/template/build-in/objects/objects.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/template/build-in/vars/vars.go b/.example/net/ghttp/server/template/build-in/vars/vars.go index 2e9b37027..0d6544202 100644 --- a/.example/net/ghttp/server/template/build-in/vars/vars.go +++ b/.example/net/ghttp/server/template/build-in/vars/vars.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/template/config/config.go b/.example/net/ghttp/server/template/config/config.go index f09b8f9ae..94eaa48d6 100644 --- a/.example/net/ghttp/server/template/config/config.go +++ b/.example/net/ghttp/server/template/config/config.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/template/conflicts-name/client.go b/.example/net/ghttp/server/template/conflicts-name/client.go index 48786e7a8..c82e35f1a 100644 --- a/.example/net/ghttp/server/template/conflicts-name/client.go +++ b/.example/net/ghttp/server/template/conflicts-name/client.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) // https://github.com/gogf/gf/issues/437 diff --git a/.example/net/ghttp/server/template/layout/main.go b/.example/net/ghttp/server/template/layout/main.go index 439589e4b..9040ced33 100644 --- a/.example/net/ghttp/server/template/layout/main.go +++ b/.example/net/ghttp/server/template/layout/main.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/template/tpl1/tpl1.go b/.example/net/ghttp/server/template/tpl1/tpl1.go index d10af71b9..da6d18b0e 100644 --- a/.example/net/ghttp/server/template/tpl1/tpl1.go +++ b/.example/net/ghttp/server/template/tpl1/tpl1.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/template/tpl2/main.go b/.example/net/ghttp/server/template/tpl2/main.go index c933cb678..8489511eb 100644 --- a/.example/net/ghttp/server/template/tpl2/main.go +++ b/.example/net/ghttp/server/template/tpl2/main.go @@ -1,9 +1,9 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/frame/gins" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/frame/gins" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/net/ghttp/server/websocket/echo-wss/main.go b/.example/net/ghttp/server/websocket/echo-wss/main.go index 07d312d71..32689e893 100644 --- a/.example/net/ghttp/server/websocket/echo-wss/main.go +++ b/.example/net/ghttp/server/websocket/echo-wss/main.go @@ -1,10 +1,10 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/os/gfile" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/gfile" + "github.com/gogf/gf/v2/os/glog" ) func main() { diff --git a/.example/net/ghttp/server/websocket/echo/main-group.go b/.example/net/ghttp/server/websocket/echo/main-group.go index fd7acd90e..5a6cd8285 100644 --- a/.example/net/ghttp/server/websocket/echo/main-group.go +++ b/.example/net/ghttp/server/websocket/echo/main-group.go @@ -1,10 +1,10 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/os/gfile" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/gfile" + "github.com/gogf/gf/v2/os/glog" ) func ws(r *ghttp.Request) { diff --git a/.example/net/ghttp/server/websocket/echo/main.go b/.example/net/ghttp/server/websocket/echo/main.go index daa3f419c..61e45cebb 100644 --- a/.example/net/ghttp/server/websocket/echo/main.go +++ b/.example/net/ghttp/server/websocket/echo/main.go @@ -1,10 +1,10 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/os/gfile" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/gfile" + "github.com/gogf/gf/v2/os/glog" ) func main() { diff --git a/.example/net/gsmtp/gsmtp_sendMail.go b/.example/net/gsmtp/gsmtp_sendMail.go index f32cd7f38..307dbe24f 100644 --- a/.example/net/gsmtp/gsmtp_sendMail.go +++ b/.example/net/gsmtp/gsmtp_sendMail.go @@ -8,7 +8,7 @@ package main import ( "fmt" - "github.com/gogf/gf/net/gsmtp" + "github.com/gogf/gf/v2/net/gsmtp" ) func main() { diff --git a/.example/net/gtcp/gtcp_conn.go b/.example/net/gtcp/gtcp_conn.go index a312c4ead..855c10901 100644 --- a/.example/net/gtcp/gtcp_conn.go +++ b/.example/net/gtcp/gtcp_conn.go @@ -5,8 +5,8 @@ import ( "fmt" "os" - "github.com/gogf/gf/net/gtcp" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/net/gtcp" + "github.com/gogf/gf/v2/util/gconv" ) func main() { @@ -16,7 +16,7 @@ func main() { } defer conn.Close() - if err := conn.Send([]byte("GET / HTTP/1.1\n\n")); err != nil { + if err := conn.Send([]byte("GET / HTTP/1.1\r\n\r\n")); err != nil { panic(err) } @@ -30,13 +30,14 @@ func main() { array := bytes.Split(data, []byte(": ")) // 获得页面内容长度 if contentLength == 0 && len(array) == 2 && bytes.EqualFold([]byte("Content-Length"), array[0]) { - contentLength = gconv.Int(array[1]) + // http 以\r\n换行,需要把\r也去掉 + contentLength = gconv.Int(string(array[1][:len(array[1])-1])) } header = append(header, data...) header = append(header, '\n') } - // header读取完毕,读取文本内容 - if contentLength > 0 && len(data) == 0 { + // header读取完毕,读取文本内容, 1为\r + if contentLength > 0 && len(data) == 1 { content, _ = conn.Recv(contentLength) break } diff --git a/.example/net/gtcp/gtcp_echo_server.go b/.example/net/gtcp/gtcp_echo_server.go index 5f3d481e9..85f60832c 100644 --- a/.example/net/gtcp/gtcp_echo_server.go +++ b/.example/net/gtcp/gtcp_echo_server.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/net/gtcp" + "github.com/gogf/gf/v2/net/gtcp" ) func main() { diff --git a/.example/net/gtcp/gtcp_func.go b/.example/net/gtcp/gtcp_func.go index bca7df226..79217a973 100644 --- a/.example/net/gtcp/gtcp_func.go +++ b/.example/net/gtcp/gtcp_func.go @@ -4,7 +4,7 @@ import ( "fmt" "os" - "github.com/gogf/gf/net/gtcp" + "github.com/gogf/gf/v2/net/gtcp" ) func main() { diff --git a/.example/net/gtcp/gtcp_pool1.go b/.example/net/gtcp/gtcp_pool1.go index 69c2a491a..200d5e5dd 100644 --- a/.example/net/gtcp/gtcp_pool1.go +++ b/.example/net/gtcp/gtcp_pool1.go @@ -4,9 +4,9 @@ import ( "fmt" "time" - "github.com/gogf/gf/net/gtcp" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/net/gtcp" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gtime" ) func main() { diff --git a/.example/net/gtcp/gtcp_pool2.go b/.example/net/gtcp/gtcp_pool2.go index c30ad647d..3032ebfa9 100644 --- a/.example/net/gtcp/gtcp_pool2.go +++ b/.example/net/gtcp/gtcp_pool2.go @@ -4,9 +4,9 @@ import ( "fmt" "time" - "github.com/gogf/gf/net/gtcp" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/net/gtcp" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gtime" ) func main() { diff --git a/.example/net/gtcp/gtcp_server_client1.go b/.example/net/gtcp/gtcp_server_client1.go index 8f153aa31..076d455d6 100644 --- a/.example/net/gtcp/gtcp_server_client1.go +++ b/.example/net/gtcp/gtcp_server_client1.go @@ -4,9 +4,9 @@ import ( "fmt" "time" - "github.com/gogf/gf/net/gtcp" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/net/gtcp" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/util/gconv" ) func main() { diff --git a/.example/net/gtcp/gtcp_server_client2.go b/.example/net/gtcp/gtcp_server_client2.go index 0c89832dc..5ff8fc79d 100644 --- a/.example/net/gtcp/gtcp_server_client2.go +++ b/.example/net/gtcp/gtcp_server_client2.go @@ -4,9 +4,9 @@ import ( "fmt" "time" - "github.com/gogf/gf/net/gtcp" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/net/gtcp" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gtime" ) func main() { diff --git a/.example/net/gtcp/gtcp_timeout_client.go b/.example/net/gtcp/gtcp_timeout_client.go index e4a777282..b3777f72f 100644 --- a/.example/net/gtcp/gtcp_timeout_client.go +++ b/.example/net/gtcp/gtcp_timeout_client.go @@ -3,9 +3,9 @@ package main import ( "time" - "github.com/gogf/gf/net/gtcp" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/net/gtcp" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gtime" ) func main() { diff --git a/.example/net/gtcp/gtcp_timeout_server.go b/.example/net/gtcp/gtcp_timeout_server.go index eee3a748c..69c8592da 100644 --- a/.example/net/gtcp/gtcp_timeout_server.go +++ b/.example/net/gtcp/gtcp_timeout_server.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/gogf/gf/net/gtcp" + "github.com/gogf/gf/v2/net/gtcp" ) func main() { diff --git a/.example/net/gtcp/pkg_operations/common/funcs/funcs.go b/.example/net/gtcp/pkg_operations/common/funcs/funcs.go index 368874c1e..dfa2eb883 100644 --- a/.example/net/gtcp/pkg_operations/common/funcs/funcs.go +++ b/.example/net/gtcp/pkg_operations/common/funcs/funcs.go @@ -4,8 +4,8 @@ import ( "encoding/json" "fmt" - "github.com/gogf/gf/.example/net/gtcp/pkg_operations/common/types" - "github.com/gogf/gf/net/gtcp" + "github.com/gogf/gf/v2/.example/net/gtcp/pkg_operations/common/types" + "github.com/gogf/gf/v2/net/gtcp" ) // 自定义格式发送消息包 diff --git a/.example/net/gtcp/pkg_operations/common/gtcp_common_client.go b/.example/net/gtcp/pkg_operations/common/gtcp_common_client.go index 5d4c5f5c1..160878d39 100644 --- a/.example/net/gtcp/pkg_operations/common/gtcp_common_client.go +++ b/.example/net/gtcp/pkg_operations/common/gtcp_common_client.go @@ -3,11 +3,11 @@ package main import ( "time" - "github.com/gogf/gf/.example/net/gtcp/pkg_operations/common/funcs" - "github.com/gogf/gf/.example/net/gtcp/pkg_operations/common/types" - "github.com/gogf/gf/net/gtcp" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gtimer" + "github.com/gogf/gf/v2/.example/net/gtcp/pkg_operations/common/funcs" + "github.com/gogf/gf/v2/.example/net/gtcp/pkg_operations/common/types" + "github.com/gogf/gf/v2/net/gtcp" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gtimer" ) func main() { @@ -32,7 +32,7 @@ func main() { msg, err := funcs.RecvPkg(conn) if err != nil { if err.Error() == "EOF" { - glog.Println("server closed") + glog.Print("server closed") } break } diff --git a/.example/net/gtcp/pkg_operations/common/gtcp_common_server.go b/.example/net/gtcp/pkg_operations/common/gtcp_common_server.go index e9a8d4a74..b335db92e 100644 --- a/.example/net/gtcp/pkg_operations/common/gtcp_common_server.go +++ b/.example/net/gtcp/pkg_operations/common/gtcp_common_server.go @@ -3,11 +3,11 @@ package main import ( "time" - "github.com/gogf/gf/.example/net/gtcp/pkg_operations/common/funcs" - "github.com/gogf/gf/.example/net/gtcp/pkg_operations/common/types" - "github.com/gogf/gf/net/gtcp" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gtimer" + "github.com/gogf/gf/v2/.example/net/gtcp/pkg_operations/common/funcs" + "github.com/gogf/gf/v2/.example/net/gtcp/pkg_operations/common/types" + "github.com/gogf/gf/v2/net/gtcp" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gtimer" ) func main() { @@ -21,7 +21,7 @@ func main() { msg, err := funcs.RecvPkg(conn) if err != nil { if err.Error() == "EOF" { - glog.Println("client closed") + glog.Print("client closed") } break } diff --git a/.example/net/gtcp/pkg_operations/gtcp_basic.go b/.example/net/gtcp/pkg_operations/gtcp_basic.go index 8927f0586..88c314b50 100644 --- a/.example/net/gtcp/pkg_operations/gtcp_basic.go +++ b/.example/net/gtcp/pkg_operations/gtcp_basic.go @@ -4,9 +4,9 @@ import ( "fmt" "time" - "github.com/gogf/gf/net/gtcp" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/net/gtcp" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/util/gconv" ) func main() { diff --git a/.example/net/gtcp/pkg_operations/gtcp_empty_data.go b/.example/net/gtcp/pkg_operations/gtcp_empty_data.go index d525ae23a..ba20cbad6 100644 --- a/.example/net/gtcp/pkg_operations/gtcp_empty_data.go +++ b/.example/net/gtcp/pkg_operations/gtcp_empty_data.go @@ -4,8 +4,8 @@ import ( "fmt" "time" - "github.com/gogf/gf/net/gtcp" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/net/gtcp" + "github.com/gogf/gf/v2/os/glog" ) func main() { diff --git a/.example/net/gtcp/pkg_operations/gtcp_pkg_option.go b/.example/net/gtcp/pkg_operations/gtcp_pkg_option.go index 2a2d7dccf..41c6ba20b 100644 --- a/.example/net/gtcp/pkg_operations/gtcp_pkg_option.go +++ b/.example/net/gtcp/pkg_operations/gtcp_pkg_option.go @@ -4,9 +4,9 @@ import ( "fmt" "time" - "github.com/gogf/gf/net/gtcp" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/net/gtcp" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/util/gconv" ) func main() { diff --git a/.example/net/gtcp/pkg_operations/monitor/gtcp_monitor_client.go b/.example/net/gtcp/pkg_operations/monitor/gtcp_monitor_client.go index 7ce623e40..6f150f410 100644 --- a/.example/net/gtcp/pkg_operations/monitor/gtcp_monitor_client.go +++ b/.example/net/gtcp/pkg_operations/monitor/gtcp_monitor_client.go @@ -3,11 +3,11 @@ package main import ( "encoding/json" - "github.com/gogf/gf/.example/net/gtcp/pkg_operations/monitor/types" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/gtcp" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/.example/net/gtcp/pkg_operations/monitor/types" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/gtcp" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gtime" ) func main() { @@ -35,9 +35,9 @@ func main() { // 使用 SendRecvPkg 发送消息包并接受返回 if result, err := conn.SendRecvPkg(info); err != nil { if err.Error() == "EOF" { - glog.Println("server closed") + glog.Print("server closed") } } else { - glog.Println(string(result)) + glog.Print(string(result)) } } diff --git a/.example/net/gtcp/pkg_operations/monitor/gtcp_monitor_server.go b/.example/net/gtcp/pkg_operations/monitor/gtcp_monitor_server.go index b9758f893..056c0a498 100644 --- a/.example/net/gtcp/pkg_operations/monitor/gtcp_monitor_server.go +++ b/.example/net/gtcp/pkg_operations/monitor/gtcp_monitor_server.go @@ -3,9 +3,9 @@ package main import ( "encoding/json" - "github.com/gogf/gf/.example/net/gtcp/pkg_operations/monitor/types" - "github.com/gogf/gf/net/gtcp" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/.example/net/gtcp/pkg_operations/monitor/types" + "github.com/gogf/gf/v2/net/gtcp" + "github.com/gogf/gf/v2/os/glog" ) func main() { @@ -16,7 +16,7 @@ func main() { data, err := conn.RecvPkg() if err != nil { if err.Error() == "EOF" { - glog.Println("client closed") + glog.Print("client closed") } break } @@ -24,7 +24,7 @@ func main() { if err := json.Unmarshal(data, info); err != nil { glog.Errorf("invalid package structure: %s", err.Error()) } else { - glog.Println(info) + glog.Print(info) conn.SendPkg([]byte("ok")) } } diff --git a/.example/net/gtcp/pkg_operations/monitor/types/types.go b/.example/net/gtcp/pkg_operations/monitor/types/types.go index d0c43ed09..2d6b6b7cf 100644 --- a/.example/net/gtcp/pkg_operations/monitor/types/types.go +++ b/.example/net/gtcp/pkg_operations/monitor/types/types.go @@ -1,6 +1,6 @@ package types -import "github.com/gogf/gf/frame/g" +import "github.com/gogf/gf/v2/frame/g" type NodeInfo struct { Cpu float32 // CPU百分比(%) diff --git a/.example/net/gtcp/server_client/gtcp_client.go b/.example/net/gtcp/server_client/gtcp_client.go index a991cad7a..be580a6ef 100644 --- a/.example/net/gtcp/server_client/gtcp_client.go +++ b/.example/net/gtcp/server_client/gtcp_client.go @@ -3,9 +3,9 @@ package main import ( "time" - "github.com/gogf/gf/net/gtcp" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/net/gtcp" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/util/gconv" ) func main() { diff --git a/.example/net/gtcp/server_client/gtcp_server.go b/.example/net/gtcp/server_client/gtcp_server.go index e814f31e8..92df614f7 100644 --- a/.example/net/gtcp/server_client/gtcp_server.go +++ b/.example/net/gtcp/server_client/gtcp_server.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/net/gtcp" + "github.com/gogf/gf/v2/net/gtcp" ) func main() { diff --git a/.example/net/gtcp/tls/gtcp_server_client.go b/.example/net/gtcp/tls/gtcp_server_client.go index e478620cc..87d5bb981 100644 --- a/.example/net/gtcp/tls/gtcp_server_client.go +++ b/.example/net/gtcp/tls/gtcp_server_client.go @@ -4,9 +4,9 @@ import ( "fmt" "time" - "github.com/gogf/gf/net/gtcp" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/net/gtcp" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/util/gconv" ) func main() { diff --git a/.example/net/gudp/gudp_server.go b/.example/net/gudp/gudp_server.go index b3d739798..ba59eaf75 100644 --- a/.example/net/gudp/gudp_server.go +++ b/.example/net/gudp/gudp_server.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/net/gudp" + "github.com/gogf/gf/v2/net/gudp" ) func main() { diff --git a/.example/net/gudp/gudp_server_client.go b/.example/net/gudp/gudp_server_client.go index 720e1052e..a19512ee0 100644 --- a/.example/net/gudp/gudp_server_client.go +++ b/.example/net/gudp/gudp_server_client.go @@ -4,9 +4,9 @@ import ( "fmt" "time" - "github.com/gogf/gf/net/gudp" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/net/gudp" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gtime" ) func main() { diff --git a/.example/os/gbuild/gbuild.go b/.example/os/gbuild/gbuild.go index 486371b31..5759c3d18 100644 --- a/.example/os/gbuild/gbuild.go +++ b/.example/os/gbuild/gbuild.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/os/gbuild" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gbuild" ) func main() { diff --git a/.example/os/gcache/getorset_func_lock.go b/.example/os/gcache/getorset_func_lock.go new file mode 100644 index 000000000..1d909597d --- /dev/null +++ b/.example/os/gcache/getorset_func_lock.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/gogf/gf/v2/os/gcache" + "github.com/gogf/gf/v2/os/gctx" + "time" +) + +func main() { + var ( + ch = make(chan struct{}, 0) + ctx = gctx.New() + key = `key` + value = `value` + ) + for i := 0; i < 10; i++ { + go func(index int) { + <-ch + _, _ = gcache.Ctx(ctx).GetOrSetFuncLock(key, func() (interface{}, error) { + fmt.Println(index, "entered") + return value, nil + }, 0) + }(i) + } + close(ch) + time.Sleep(time.Second) +} diff --git a/.example/os/gcache/note_interface_key.go b/.example/os/gcache/note_interface_key.go new file mode 100644 index 000000000..08733d7ec --- /dev/null +++ b/.example/os/gcache/note_interface_key.go @@ -0,0 +1,19 @@ +package main + +import ( + "fmt" + "github.com/gogf/gf/v2/os/gcache" + "github.com/gogf/gf/v2/os/gctx" +) + +func main() { + var ( + ctx = gctx.New() + key1 int32 = 1 + key2 float64 = 1 + value = `value` + ) + _ = gcache.Ctx(ctx).Set(key1, value, 0) + fmt.Println(gcache.Ctx(ctx).Get(key1)) + fmt.Println(gcache.Ctx(ctx).Get(key2)) +} diff --git a/.example/os/gcache/note_interface_value.go b/.example/os/gcache/note_interface_value.go new file mode 100644 index 000000000..1d121c9ab --- /dev/null +++ b/.example/os/gcache/note_interface_value.go @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "github.com/gogf/gf/v2/os/gcache" + "github.com/gogf/gf/v2/os/gctx" +) + +func main() { + type User struct { + Id int + Name string + Site string + } + var ( + ctx = gctx.New() + user *User + key = `UserKey` + value = &User{ + Id: 1, + Name: "GoFrame", + Site: "https://goframe.org", + } + ) + _ = gcache.Ctx(ctx).Set(key, value, 0) + v, _ := gcache.Ctx(ctx).GetVar(key) + _ = v.Scan(&user) + fmt.Printf(`%#v`, user) +} diff --git a/.example/os/gcache/usage_basic.go b/.example/os/gcache/usage_basic.go index a60450689..cc1fa632e 100644 --- a/.example/os/gcache/usage_basic.go +++ b/.example/os/gcache/usage_basic.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/os/gcache" + "github.com/gogf/gf/v2/os/gcache" ) func main() { diff --git a/.example/os/gcache/usage_lru.go b/.example/os/gcache/usage_lru.go index 7671c311d..bbf897530 100644 --- a/.example/os/gcache/usage_lru.go +++ b/.example/os/gcache/usage_lru.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/gogf/gf/os/gcache" + "github.com/gogf/gf/v2/os/gcache" ) func main() { diff --git a/.example/os/gcache/usage_senior.go b/.example/os/gcache/usage_senior.go index b82a48344..ac5b4f113 100644 --- a/.example/os/gcache/usage_senior.go +++ b/.example/os/gcache/usage_senior.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/gogf/gf/os/gcache" + "github.com/gogf/gf/v2/os/gcache" ) func main() { diff --git a/.example/os/gcfg/basic/gcfg1.go b/.example/os/gcfg/basic/gcfg1.go index 722793aba..2665ebbba 100644 --- a/.example/os/gcfg/basic/gcfg1.go +++ b/.example/os/gcfg/basic/gcfg1.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) // 使用第二个参数指定读取的配置文件 diff --git a/.example/os/gcfg/basic/gcfg2.go b/.example/os/gcfg/basic/gcfg2.go index 464deaee7..3ccbe7e12 100644 --- a/.example/os/gcfg/basic/gcfg2.go +++ b/.example/os/gcfg/basic/gcfg2.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) // 使用默认的config.toml配置文件读取配置 diff --git a/.example/os/gcfg/basic/gcfg3.go b/.example/os/gcfg/basic/gcfg3.go index ebc6c994e..fc95f57c1 100644 --- a/.example/os/gcfg/basic/gcfg3.go +++ b/.example/os/gcfg/basic/gcfg3.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) // 使用GetVar获取动态变量 diff --git a/.example/os/gcfg/basic/gcfg4.go b/.example/os/gcfg/basic/gcfg4.go index 321ed03a7..a2af5a2d9 100644 --- a/.example/os/gcfg/basic/gcfg4.go +++ b/.example/os/gcfg/basic/gcfg4.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) // 使用g.Config方法获取配置管理对象,并指定默认的配置文件名称 diff --git a/.example/os/gcfg/basic/gcfg_auto_update.go b/.example/os/gcfg/basic/gcfg_auto_update.go index 7dd2e6bff..cd01884d1 100644 --- a/.example/os/gcfg/basic/gcfg_auto_update.go +++ b/.example/os/gcfg/basic/gcfg_auto_update.go @@ -4,9 +4,9 @@ import ( "fmt" "time" - "github.com/gogf/gf/os/gtimer" + "github.com/gogf/gf/v2/os/gtimer" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) // 配置文件热更新示例 diff --git a/.example/os/gcfg/basic/gcfg_error.go b/.example/os/gcfg/basic/gcfg_error.go index b0bc88f72..2df606679 100644 --- a/.example/os/gcfg/basic/gcfg_error.go +++ b/.example/os/gcfg/basic/gcfg_error.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { diff --git a/.example/os/gcfg/resource/resource.go b/.example/os/gcfg/resource/resource.go index 9a9aa3c51..9f646fc3e 100644 --- a/.example/os/gcfg/resource/resource.go +++ b/.example/os/gcfg/resource/resource.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - _ "github.com/gogf/gf/os/gres/testdata" + "github.com/gogf/gf/v2/frame/g" + _ "github.com/gogf/gf/v2/os/gres/testdata" ) func main() { diff --git a/.example/os/gcmd/main.go b/.example/os/gcmd/main.go index 3cae98c12..21f1d1a54 100644 --- a/.example/os/gcmd/main.go +++ b/.example/os/gcmd/main.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/os/gcmd" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gcmd" ) func main() { diff --git a/.example/os/gcron/gcron-log.go b/.example/os/gcron/gcron-log.go index 3a87ec5b9..d77aa1a4b 100644 --- a/.example/os/gcron/gcron-log.go +++ b/.example/os/gcron/gcron-log.go @@ -3,14 +3,14 @@ package main import ( "time" - "github.com/gogf/gf/os/gcron" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/os/gcron" + "github.com/gogf/gf/v2/os/glog" ) func main() { gcron.SetLogLevel(glog.LEVEL_ALL) gcron.Add("* * * * * ?", func() { - glog.Println("test") + glog.Print("test") }) time.Sleep(3 * time.Second) } diff --git a/.example/os/gcron/gcron1.go b/.example/os/gcron/gcron1.go index 4e14cca8f..6b90aec61 100644 --- a/.example/os/gcron/gcron1.go +++ b/.example/os/gcron/gcron1.go @@ -3,19 +3,19 @@ package main import ( "time" - "github.com/gogf/gf/os/gcron" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/os/gcron" + "github.com/gogf/gf/v2/os/glog" ) func main() { - gcron.Add("0 30 * * * *", func() { glog.Println("Every hour on the half hour") }) - gcron.Add("* * * * * *", func() { glog.Println("Every second, pattern") }, "second-cron") - gcron.Add("*/5 * * * * *", func() { glog.Println("Every 5 seconds, pattern") }) + gcron.Add("0 30 * * * *", func() { glog.Print("Every hour on the half hour") }) + gcron.Add("* * * * * *", func() { glog.Print("Every second, pattern") }, "second-cron") + gcron.Add("*/5 * * * * *", func() { glog.Print("Every 5 seconds, pattern") }) - gcron.Add("@hourly", func() { glog.Println("Every hour") }) - gcron.Add("@every 1h30m", func() { glog.Println("Every hour thirty") }) - gcron.Add("@every 1s", func() { glog.Println("Every 1 second") }) - gcron.Add("@every 5s", func() { glog.Println("Every 5 seconds") }) + gcron.Add("@hourly", func() { glog.Print("Every hour") }) + gcron.Add("@every 1h30m", func() { glog.Print("Every hour thirty") }) + gcron.Add("@every 1s", func() { glog.Print("Every 1 second") }) + gcron.Add("@every 5s", func() { glog.Print("Every 5 seconds") }) time.Sleep(3 * time.Second) diff --git a/.example/os/gcron/gcron2.go b/.example/os/gcron/gcron2.go index e5ea85ec9..bc032dba1 100644 --- a/.example/os/gcron/gcron2.go +++ b/.example/os/gcron/gcron2.go @@ -3,12 +3,12 @@ package main import ( "time" - "github.com/gogf/gf/os/gcron" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/os/gcron" + "github.com/gogf/gf/v2/os/glog" ) func test() { - glog.Println(111) + glog.Print(111) } func main() { diff --git a/.example/os/gfile/gfile.go b/.example/os/gfile/gfile.go index f3cc69d74..b84ca4a97 100644 --- a/.example/os/gfile/gfile.go +++ b/.example/os/gfile/gfile.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/os/gfile" - "github.com/gogf/gf/util/gutil" + "github.com/gogf/gf/v2/os/gfile" + "github.com/gogf/gf/v2/util/gutil" ) var dirpath1 = "/home/john/Workspace/temp/" diff --git a/.example/os/gfile/gfile_contents.go b/.example/os/gfile/gfile_contents.go index f972ee707..cfd8eda7f 100644 --- a/.example/os/gfile/gfile_contents.go +++ b/.example/os/gfile/gfile_contents.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/os/gfile" + "github.com/gogf/gf/v2/os/gfile" ) func main() { diff --git a/.example/os/gfile/gfile_scan.go b/.example/os/gfile/gfile_scan.go index 08120909a..bb032562a 100644 --- a/.example/os/gfile/gfile_scan.go +++ b/.example/os/gfile/gfile_scan.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/os/gfile" - "github.com/gogf/gf/util/gutil" + "github.com/gogf/gf/v2/os/gfile" + "github.com/gogf/gf/v2/util/gutil" ) func main() { diff --git a/.example/os/gfpool/gfpool.go b/.example/os/gfpool/gfpool.go index 48090606e..dbbae303f 100644 --- a/.example/os/gfpool/gfpool.go +++ b/.example/os/gfpool/gfpool.go @@ -5,7 +5,7 @@ import ( "os" "time" - "github.com/gogf/gf/os/gfpool" + "github.com/gogf/gf/v2/os/gfpool" ) func main() { diff --git a/.example/os/gfsnotify/fsnotify.go b/.example/os/gfsnotify/fsnotify.go index 8b473729f..833732398 100644 --- a/.example/os/gfsnotify/fsnotify.go +++ b/.example/os/gfsnotify/fsnotify.go @@ -1,10 +1,11 @@ package main import ( + "context" "log" "github.com/fsnotify/fsnotify" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/os/glog" ) func main() { @@ -25,7 +26,7 @@ func main() { for { select { case ev := <-watch.Events: - glog.Println(ev) + glog.Print(context.Background(), ev) case err := <-watch.Errors: log.Println("error : ", err) diff --git a/.example/os/gfsnotify/gfsnotify.go b/.example/os/gfsnotify/gfsnotify.go index cb5c87dc1..deedea686 100644 --- a/.example/os/gfsnotify/gfsnotify.go +++ b/.example/os/gfsnotify/gfsnotify.go @@ -1,15 +1,15 @@ package main import ( - "github.com/gogf/gf/os/gfsnotify" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/os/gfsnotify" + "github.com/gogf/gf/v2/os/glog" ) func main() { //path := `D:\temp` path := "/Users/john/Temp" _, err := gfsnotify.Add(path, func(event *gfsnotify.Event) { - glog.Println(event) + glog.Print(event) }) if err != nil { glog.Fatal(err) diff --git a/.example/os/gfsnotify/gfsnotify_callback.go b/.example/os/gfsnotify/gfsnotify_callback.go index 897aedda1..f6e864d9e 100644 --- a/.example/os/gfsnotify/gfsnotify_callback.go +++ b/.example/os/gfsnotify/gfsnotify_callback.go @@ -3,20 +3,20 @@ package main import ( "time" - "github.com/gogf/gf/os/gfsnotify" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gtimer" + "github.com/gogf/gf/v2/os/gfsnotify" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gtimer" ) func main() { c1, err := gfsnotify.Add("/home/john/temp/log", func(event *gfsnotify.Event) { - glog.Println("callback1") + glog.Print("callback1") }) if err != nil { panic(err) } c2, err := gfsnotify.Add("/home/john/temp/log", func(event *gfsnotify.Event) { - glog.Println("callback2") + glog.Print("callback2") }) if err != nil { panic(err) @@ -24,12 +24,12 @@ func main() { // 5秒后移除c1的回调函数注册,仅剩c2 gtimer.SetTimeout(5*time.Second, func() { gfsnotify.RemoveCallback(c1.Id) - glog.Println("remove callback c1") + glog.Print("remove callback c1") }) // 10秒后移除c2的回调函数注册,所有的回调都移除,不再有任何打印信息输出 gtimer.SetTimeout(10*time.Second, func() { gfsnotify.RemoveCallback(c2.Id) - glog.Println("remove callback c2") + glog.Print("remove callback c2") }) select {} diff --git a/.example/os/gfsnotify/gfsnotify_callback_folder.go b/.example/os/gfsnotify/gfsnotify_callback_folder.go index d94514790..a12d70f89 100644 --- a/.example/os/gfsnotify/gfsnotify_callback_folder.go +++ b/.example/os/gfsnotify/gfsnotify_callback_folder.go @@ -1,16 +1,20 @@ package main import ( + "context" "time" - "github.com/gogf/gf/os/gfsnotify" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gtimer" + "github.com/gogf/gf/v2/os/gfsnotify" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gtimer" ) func main() { + var ( + ctx = context.Background() + ) callback, err := gfsnotify.Add("/home/john/temp", func(event *gfsnotify.Event) { - glog.Println("callback") + glog.Print(ctx, "callback") }) if err != nil { panic(err) @@ -19,9 +23,9 @@ func main() { // 在此期间创建文件、目录、修改文件、删除文件 // 20秒后移除回调函数注册,所有的回调都移除,不再有任何打印信息输出 - gtimer.SetTimeout(20*time.Second, func() { + gtimer.SetTimeout(ctx, 20*time.Second, func(ctx context.Context) { gfsnotify.RemoveCallback(callback.Id) - glog.Println("remove callback") + glog.Print(ctx, "remove callback") }) select {} diff --git a/.example/os/gfsnotify/gfsnotify_limit.go b/.example/os/gfsnotify/gfsnotify_limit.go index 600541bf9..33522de5c 100644 --- a/.example/os/gfsnotify/gfsnotify_limit.go +++ b/.example/os/gfsnotify/gfsnotify_limit.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/os/gfsnotify" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/os/gfsnotify" + "github.com/gogf/gf/v2/os/glog" ) // 对同一个文件多次Add是否超过系统inotify限制 @@ -10,7 +10,7 @@ func main() { path := "/Users/john/temp/log" for i := 0; i < 9999999; i++ { _, err := gfsnotify.Add(path, func(event *gfsnotify.Event) { - glog.Println(event) + glog.Print(event) }) if err != nil { glog.Fatal(err) diff --git a/.example/os/glog/glog_CtxKeys.go b/.example/os/glog/glog_CtxKeys.go new file mode 100644 index 000000000..dff0efc78 --- /dev/null +++ b/.example/os/glog/glog_CtxKeys.go @@ -0,0 +1,14 @@ +package main + +import ( + "context" + "github.com/gogf/gf/v2/frame/g" +) + +func main() { + g.Log().SetCtxKeys("TraceId", "SpanId", "Test") + ctx := context.WithValue(context.Background(), "TraceId", "1234567890") + ctx = context.WithValue(ctx, "SpanId", "abcdefg") + + g.Log().Ctx(ctx).Print(1, 2, 3) +} diff --git a/.example/os/glog/glog_config1.go b/.example/os/glog/glog_SetConfigWithMap.go similarity index 52% rename from .example/os/glog/glog_config1.go rename to .example/os/glog/glog_SetConfigWithMap.go index fc3c5a3cb..d20e70882 100644 --- a/.example/os/glog/glog_config1.go +++ b/.example/os/glog/glog_SetConfigWithMap.go @@ -1,12 +1,12 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/glog" ) func main() { - err := glog.SetConfigWithMap(g.Map{ + err := g.Log().SetConfigWithMap(g.Map{ "prefix": "[TEST]", }) if err != nil { diff --git a/.example/os/glog/glog_async1.go b/.example/os/glog/glog_async_chaining.go similarity index 58% rename from .example/os/glog/glog_async1.go rename to .example/os/glog/glog_async_chaining.go index 1f17d1c25..e5bd8088a 100644 --- a/.example/os/glog/glog_async1.go +++ b/.example/os/glog/glog_async_chaining.go @@ -1,14 +1,13 @@ package main import ( + "github.com/gogf/gf/v2/frame/g" "time" - - "github.com/gogf/gf/os/glog" ) func main() { for i := 0; i < 10; i++ { - glog.Async().Print("async log", i) + g.Log().Async().Print("async log", i) } time.Sleep(time.Second) } diff --git a/.example/os/glog/glog_async2.go b/.example/os/glog/glog_async_configure.go similarity index 54% rename from .example/os/glog/glog_async2.go rename to .example/os/glog/glog_async_configure.go index 63d6f4278..ed4071e92 100644 --- a/.example/os/glog/glog_async2.go +++ b/.example/os/glog/glog_async_configure.go @@ -1,15 +1,14 @@ package main import ( + "github.com/gogf/gf/v2/frame/g" "time" - - "github.com/gogf/gf/os/glog" ) func main() { - glog.SetAsync(true) + g.Log().SetAsync(true) for i := 0; i < 10; i++ { - glog.Async().Print("async log", i) + g.Log().Print("async log", i) } time.Sleep(time.Second) } diff --git a/.example/os/glog/glog_category.go b/.example/os/glog/glog_category.go index 47c56ccf4..1aa9a7e8f 100644 --- a/.example/os/glog/glog_category.go +++ b/.example/os/glog/glog_category.go @@ -1,15 +1,14 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/os/gfile" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gfile" ) func main() { path := "/tmp/glog-cat" - glog.SetPath(path) - glog.Stdout(false).Cat("cat1").Cat("cat2").Println("test") + g.Log().SetPath(path) + g.Log().Stdout(false).Cat("cat1").Cat("cat2").Print("test") list, err := gfile.ScanDir(path, "*", true) g.Dump(err) g.Dump(list) diff --git a/.example/os/glog/glog_color.go b/.example/os/glog/glog_color.go new file mode 100644 index 000000000..aa64f1e89 --- /dev/null +++ b/.example/os/glog/glog_color.go @@ -0,0 +1,15 @@ +package main + +import ( + "github.com/gogf/gf/v2/frame/g" +) + +func main() { + g.Log().Print("Print") + g.Log().Debug("Debug") + g.Log().Info("Info") + g.Log().Notice("Notice") + g.Log().Warning("Warning") + g.Log().Error("Error") + g.Log().Critical("Critical") +} diff --git a/.example/os/glog/glog_ctx.go b/.example/os/glog/glog_ctx.go deleted file mode 100644 index b4ca21ea2..000000000 --- a/.example/os/glog/glog_ctx.go +++ /dev/null @@ -1,14 +0,0 @@ -package main - -import ( - "context" - "github.com/gogf/gf/os/glog" -) - -func main() { - glog.SetCtxKeys("Trace-Id", "Span-Id", "Test") - ctx := context.WithValue(context.Background(), "Trace-Id", "1234567890") - ctx = context.WithValue(ctx, "Span-Id", "abcdefg") - - glog.Ctx(ctx).Print(1, 2, 3) -} diff --git a/.example/os/glog/glog_debug.go b/.example/os/glog/glog_debug.go index 64ec9c277..1129b0f3d 100644 --- a/.example/os/glog/glog_debug.go +++ b/.example/os/glog/glog_debug.go @@ -1,19 +1,19 @@ package main import ( + "github.com/gogf/gf/v2/frame/g" "time" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gtime" - "github.com/gogf/gf/os/gtimer" + "github.com/gogf/gf/v2/os/gtime" + "github.com/gogf/gf/v2/os/gtimer" ) func main() { gtimer.SetTimeout(3*time.Second, func() { - glog.SetDebug(false) + g.Log().SetDebug(false) }) for { - glog.Debug(gtime.Datetime()) + g.Log().Debug(gtime.Datetime()) time.Sleep(time.Second) } } diff --git a/.example/os/glog/glog_error.go b/.example/os/glog/glog_error.go index 3eca662b7..15e811fb7 100644 --- a/.example/os/glog/glog_error.go +++ b/.example/os/glog/glog_error.go @@ -1,6 +1,6 @@ package main -import "github.com/gogf/gf/os/glog" +import "github.com/gogf/gf/v2/os/glog" func Test() { glog.Error("This is error!") diff --git a/.example/os/glog/glog_file.go b/.example/os/glog/glog_file.go index 6a0843dac..6aa1cb7f6 100644 --- a/.example/os/glog/glog_file.go +++ b/.example/os/glog/glog_file.go @@ -1,26 +1,32 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/os/gfile" - "github.com/gogf/gf/os/glog" + "context" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gfile" ) // 设置日志等级 func main() { - l := glog.New() - path := "/tmp/glog" - l.SetPath(path) - l.SetStdoutPrint(false) + var ( + ctx = context.TODO() + path = "/tmp/glog" + ) + + g.Log().SetPath(path) + g.Log().SetStdoutPrint(false) + // 使用默认文件名称格式 - l.Println("标准文件名称格式,使用当前时间时期") + g.Log().Print(ctx, "标准文件名称格式,使用当前时间时期") + // 通过SetFile设置文件名称格式 - l.SetFile("stdout.log") - l.Println("设置日志输出文件名称格式为同一个文件") + g.Log().SetFile("stdout.log") + g.Log().Print(ctx, "设置日志输出文件名称格式为同一个文件") + // 链式操作设置文件名称格式 - l.File("stderr.log").Println("支持链式操作") - l.File("error-{Ymd}.log").Println("文件名称支持带gtime日期格式") - l.File("access-{Ymd}.log").Println("文件名称支持带gtime日期格式") + g.Log().File("stderr.log").Print(ctx, "支持链式操作") + g.Log().File("error-{Ymd}.log").Print(ctx, "文件名称支持带gtime日期格式") + g.Log().File("access-{Ymd}.log").Print(ctx, "文件名称支持带gtime日期格式") list, err := gfile.ScanDir(path, "*") g.Dump(err) diff --git a/.example/os/glog/glog_flags.go b/.example/os/glog/glog_flags.go index ebb3894c3..3ab7ea82e 100644 --- a/.example/os/glog/glog_flags.go +++ b/.example/os/glog/glog_flags.go @@ -1,15 +1,15 @@ package main import ( - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/glog" ) func main() { - l := glog.New() - l.SetFlags(glog.F_TIME_TIME | glog.F_FILE_SHORT) - l.Println("time and short line number") - l.SetFlags(glog.F_TIME_MILLI | glog.F_FILE_LONG) - l.Println("time with millisecond and long line number") - l.SetFlags(glog.F_TIME_STD | glog.F_FILE_LONG) - l.Println("standard time format and long line number") + g.Log().SetFlags(glog.F_TIME_TIME | glog.F_FILE_SHORT) + g.Log().Print("time and short line number") + g.Log().SetFlags(glog.F_TIME_MILLI | glog.F_FILE_LONG) + g.Log().Print("time with millisecond and long line number") + g.Log().SetFlags(glog.F_TIME_STD | glog.F_FILE_LONG) + g.Log().Print("standard time format and long line number") } diff --git a/.example/os/glog/glog_gerror.go b/.example/os/glog/glog_gerror.go index cbcf405c0..018a31b08 100644 --- a/.example/os/glog/glog_gerror.go +++ b/.example/os/glog/glog_gerror.go @@ -2,9 +2,9 @@ package main import ( "errors" + "github.com/gogf/gf/v2/frame/g" - "github.com/gogf/gf/errors/gerror" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/errors/gerror" ) func MakeError() error { @@ -18,8 +18,8 @@ func MakeGError() error { func TestGError() { err1 := MakeError() err2 := MakeGError() - glog.Error(err1) - glog.Error(err2) + g.Log().Error(err1) + g.Log().Error(err2) } func main() { diff --git a/.example/os/glog/glog_json.go b/.example/os/glog/glog_json.go index f1e28944e..e9285d8fe 100644 --- a/.example/os/glog/glog_json.go +++ b/.example/os/glog/glog_json.go @@ -1,16 +1,15 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/frame/g" ) func main() { - glog.Debug(g.Map{"uid": 100, "name": "john"}) + g.Log().Debug(g.Map{"uid": 100, "name": "john"}) type User struct { Uid int `json:"uid"` Name string `json:"name"` } - glog.Debug(User{100, "john"}) + g.Log().Debug(User{100, "john"}) } diff --git a/.example/os/glog/glog_level.go b/.example/os/glog/glog_level.go index c1e07f736..701f1132a 100644 --- a/.example/os/glog/glog_level.go +++ b/.example/os/glog/glog_level.go @@ -1,13 +1,13 @@ package main import ( - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/glog" ) // 设置日志等级,过滤掉Info日志信息 func main() { - l := glog.New() - l.Info("info1") - l.SetLevel(glog.LEVEL_ALL ^ glog.LEVEL_INFO) - l.Info("info2") + g.Log().Info("info1") + g.Log().SetLevel(glog.LEVEL_ALL ^ glog.LEVEL_INFO) + g.Log().Info("info2") } diff --git a/.example/os/glog/glog_level_prefix.go b/.example/os/glog/glog_level_prefix.go index cd9a7e9f7..c15687866 100644 --- a/.example/os/glog/glog_level_prefix.go +++ b/.example/os/glog/glog_level_prefix.go @@ -1,11 +1,11 @@ package main import ( - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/glog" ) func main() { - l := glog.New() - l.SetLevelPrefix(glog.LEVEL_DEBU, "debug") - l.Debug("test") + g.Log().SetLevelPrefix(glog.LEVEL_DEBU, "debug") + g.Log().Debug("test") } diff --git a/.example/os/glog/glog_line.go b/.example/os/glog/glog_line.go index 4ee2ad1a1..2d7648343 100644 --- a/.example/os/glog/glog_line.go +++ b/.example/os/glog/glog_line.go @@ -1,10 +1,10 @@ package main import ( - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/frame/g" ) func main() { - glog.Line().Debug("this is the short file name with its line number") - glog.Line(true).Debug("lone file name with line number") + g.Log().Line().Debug("this is the short file name with its line number") + g.Log().Line(true).Debug("lone file name with line number") } diff --git a/.example/os/glog/glog_line2.go b/.example/os/glog/glog_line2.go index b694f7b92..ea0011462 100644 --- a/.example/os/glog/glog_line2.go +++ b/.example/os/glog/glog_line2.go @@ -1,12 +1,12 @@ package main import ( - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/frame/g" ) func PrintLog(content string) { - glog.Skip(0).Line().Println("line number with skip:", content) - glog.Line(true).Println("line number without skip:", content) + g.Log().Skip(0).Line().Print("line number with skip:", content) + g.Log().Line(true).Print("line number without skip:", content) } func main() { diff --git a/.example/os/glog/glog_path.go b/.example/os/glog/glog_path.go index 913a037ab..64b40be32 100644 --- a/.example/os/glog/glog_path.go +++ b/.example/os/glog/glog_path.go @@ -1,16 +1,15 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/os/gfile" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gfile" ) // 设置日志输出路径 func main() { path := "/tmp/glog" - glog.SetPath(path) - glog.Println("日志内容") + g.Log().SetPath(path) + g.Log().Print("日志内容") list, err := gfile.ScanDir(path, "*") g.Dump(err) g.Dump(list) diff --git a/.example/os/glog/glog_pool.go b/.example/os/glog/glog_pool.go index 383b74367..565848e93 100644 --- a/.example/os/glog/glog_pool.go +++ b/.example/os/glog/glog_pool.go @@ -1,18 +1,18 @@ package main import ( + "github.com/gogf/gf/v2/frame/g" "time" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/os/gtime" ) // 测试删除日志文件是否会重建日志文件 func main() { path := "/Users/john/Temp/test" - glog.SetPath(path) + g.Log().SetPath(path) for { - glog.Println(gtime.Now().String()) + g.Log().Print(gtime.Now().String()) time.Sleep(time.Second) } } diff --git a/.example/os/glog/glog_prefix.go b/.example/os/glog/glog_prefix.go index 502467128..90c114354 100644 --- a/.example/os/glog/glog_prefix.go +++ b/.example/os/glog/glog_prefix.go @@ -1,12 +1,11 @@ package main import ( - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/frame/g" ) func main() { - l := glog.New() - l.SetPrefix("[API]") - l.Println("hello world") - l.Error("error occurred") + g.Log().SetPrefix("[API]") + g.Log().Print("hello world") + g.Log().Error("error occurred") } diff --git a/.example/os/glog/glog_stack.go b/.example/os/glog/glog_stack.go index 1232c2bec..854793408 100644 --- a/.example/os/glog/glog_stack.go +++ b/.example/os/glog/glog_stack.go @@ -2,15 +2,11 @@ package main import ( "fmt" - - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/frame/g" ) func main() { + g.Log().PrintStack() - glog.PrintStack() - glog.New().PrintStack() - - fmt.Println(glog.GetStack()) - fmt.Println(glog.New().GetStack()) + fmt.Println(g.Log().GetStack()) } diff --git a/.example/os/glog/glog_stdout.go b/.example/os/glog/glog_stdout.go index 4d2200028..801d65732 100644 --- a/.example/os/glog/glog_stdout.go +++ b/.example/os/glog/glog_stdout.go @@ -1,22 +1,23 @@ package main import ( + "github.com/gogf/gf/v2/frame/g" "sync" - - "github.com/gogf/gf/os/glog" ) func main() { - wg := sync.WaitGroup{} - c := make(chan struct{}) + var ( + wg = sync.WaitGroup{} + ch = make(chan struct{}) + ) wg.Add(3000) for i := 0; i < 3000; i++ { go func() { - <-c - glog.Println("abcdefghijklmnopqrstuvwxyz1234567890") + <-ch + g.Log().Print("abcdefghijklmnopqrstuvwxyz1234567890") wg.Done() }() } - close(c) + close(ch) wg.Wait() } diff --git a/.example/os/glog/glog_writer_greylog.go b/.example/os/glog/glog_writer_greylog.go index fddf60daf..4f0824a47 100644 --- a/.example/os/glog/glog_writer_greylog.go +++ b/.example/os/glog/glog_writer_greylog.go @@ -1,7 +1,7 @@ package main //import ( -// "github.com/gogf/gf/os/glog" +// "github.com/gogf/gf/v2/os/glog" // "github.com/robertkowalski/graylog-golang" //) // @@ -26,5 +26,5 @@ package main // MaxChunkSizeLan : 1337, // }), // }) -// glog.Println("test log") +// glog.Print("test log") //} diff --git a/.example/os/glog/glog_writer_hook.go b/.example/os/glog/glog_writer_hook.go index 67e8863ca..e3a6e4526 100644 --- a/.example/os/glog/glog_writer_hook.go +++ b/.example/os/glog/glog_writer_hook.go @@ -2,10 +2,10 @@ package main import ( "fmt" + "github.com/gogf/gf/v2/frame/g" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/text/gregex" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/text/gregex" ) type MyWriter struct { @@ -16,7 +16,7 @@ func (w *MyWriter) Write(p []byte) (n int, err error) { s := string(p) if gregex.IsMatchString(`\[(PANI|FATA)\]`, s) { fmt.Println("SERIOUS ISSUE OCCURRED!! I'd better tell monitor in first time!") - ghttp.PostContent("http://monitor.mydomain.com", s) + g.Client().PostContent("http://monitor.mydomain.com", s) } return w.logger.Write(p) } diff --git a/.example/os/glog/handler/glog_handler_greylog.go b/.example/os/glog/handler/glog_handler_greylog.go new file mode 100644 index 000000000..295ea11f9 --- /dev/null +++ b/.example/os/glog/handler/glog_handler_greylog.go @@ -0,0 +1,31 @@ +package main + +//import ( +// "context" +// "github.com/gogf/gf/v2/frame/g" +// "github.com/gogf/gf/v2/os/glog" +// "github.com/robertkowalski/graylog-golang" +//) +// +//var greyLogClient = gelf.New(gelf.Config{ +// GraylogPort: 80, +// GraylogHostname: "graylog-host.com", +// Connection: "wan", +// MaxChunkSizeWan: 42, +// MaxChunkSizeLan: 1337, +//}) +// +//// LoggingGreyLogHandler is an example handler for logging content to remote GreyLog service. +//var LoggingGreyLogHandler glog.Handler = func(ctx context.Context, in *glog.HandlerInput) { +// in.Next() +// greyLogClient.Log(in.Buffer.String()) +//} +// +//func main() { +// g.Log().SetHandlers(LoggingGreyLogHandler) +// +// g.Log().Debug("Debugging...") +// g.Log().Warning("It is warning info") +// g.Log().Error("Error occurs, please have a check") +// glog.Print("test log") +//} diff --git a/.example/os/glog/handler/glog_handler_json.go b/.example/os/glog/handler/glog_handler_json.go new file mode 100644 index 000000000..2e53212a8 --- /dev/null +++ b/.example/os/glog/handler/glog_handler_json.go @@ -0,0 +1,42 @@ +package main + +import ( + "context" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/internal/json" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/text/gstr" + "os" +) + +// JsonOutputsForLogger is for JSON marshaling in sequence. +type JsonOutputsForLogger struct { + Time string `json:"time"` + Level string `json:"level"` + Content string `json:"content"` +} + +// LoggingJsonHandler is an example handler for logging JSON format content. +var LoggingJsonHandler glog.Handler = func(ctx context.Context, in *glog.HandlerInput) { + jsonForLogger := JsonOutputsForLogger{ + Time: in.TimeFormat, + Level: in.LevelFormat, + Content: gstr.Trim(in.String()), + } + jsonBytes, err := json.Marshal(jsonForLogger) + if err != nil { + _, _ = os.Stderr.WriteString(err.Error()) + return + } + in.Buffer.Write(jsonBytes) + in.Buffer.WriteString("\n") + in.Next() +} + +func main() { + g.Log().SetHandlers(LoggingJsonHandler) + + g.Log().Debug("Debugging...") + g.Log().Warning("It is warning info") + g.Log().Error("Error occurs, please have a check") +} diff --git a/.example/os/gmlock/locker1.go b/.example/os/gmlock/1.lock&unlock.go similarity index 64% rename from .example/os/gmlock/locker1.go rename to .example/os/gmlock/1.lock&unlock.go index 946ae72b4..caaba0916 100644 --- a/.example/os/gmlock/locker1.go +++ b/.example/os/gmlock/1.lock&unlock.go @@ -4,19 +4,21 @@ import ( "sync" "time" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gmlock" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gmlock" ) // 内存锁基本使用 func main() { - key := "lock" - wg := sync.WaitGroup{} + var ( + key = "lock" + wg = sync.WaitGroup{} + ) for i := 0; i < 10; i++ { wg.Add(1) go func(i int) { gmlock.Lock(key) - glog.Println(i) + glog.Print(i) time.Sleep(time.Second) gmlock.Unlock(key) wg.Done() diff --git a/.example/os/gmlock/locker3.go b/.example/os/gmlock/2.trylock.go similarity index 74% rename from .example/os/gmlock/locker3.go rename to .example/os/gmlock/2.trylock.go index 6eca22f82..7fe2c421c 100644 --- a/.example/os/gmlock/locker3.go +++ b/.example/os/gmlock/2.trylock.go @@ -4,8 +4,8 @@ import ( "sync" "time" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gmlock" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gmlock" ) // 内存锁 - TryLock @@ -16,11 +16,11 @@ func main() { wg.Add(1) go func(i int) { if gmlock.TryLock(key) { - glog.Println(i) + glog.Print(i) time.Sleep(time.Second) gmlock.Unlock(key) } else { - glog.Println(false) + glog.Print(false) } wg.Done() }(i) diff --git a/.example/os/gmlock/locker4.go b/.example/os/gmlock/3.lock_conflicts.go similarity index 74% rename from .example/os/gmlock/locker4.go rename to .example/os/gmlock/3.lock_conflicts.go index 3f27939c0..712080a4a 100644 --- a/.example/os/gmlock/locker4.go +++ b/.example/os/gmlock/3.lock_conflicts.go @@ -4,8 +4,8 @@ import ( "fmt" "time" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gmlock" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gmlock" ) // 内存锁 - 手动Unlock与计时Unlock冲突校验 @@ -14,26 +14,26 @@ func main() { // 第一次锁带时间 gmlock.Lock(key) - glog.Println("lock1") + glog.Print("lock1") // 这个时候上一次的计时解锁已失效 gmlock.Unlock(key) - glog.Println("unlock1") + glog.Print("unlock1") fmt.Println() // 第二次锁,不带时间,且在执行过程中钱一个Lock的定时解锁生效 gmlock.Lock(key) - glog.Println("lock2") + glog.Print("lock2") go func() { // 正常情况下3秒后才能执行这句 gmlock.Lock(key) - glog.Println("lock by goroutine") + glog.Print("lock by goroutine") }() time.Sleep(3 * time.Second) // 这时再解锁 gmlock.Unlock(key) // 注意3秒之后才会执行这一句 - glog.Println("unlock2") + glog.Print("unlock2") select {} } diff --git a/.example/os/gmlock/test_locker.go b/.example/os/gmlock/4.test_deadlock.go similarity index 89% rename from .example/os/gmlock/test_locker.go rename to .example/os/gmlock/4.test_deadlock.go index 3600e36b6..9bc74976f 100644 --- a/.example/os/gmlock/test_locker.go +++ b/.example/os/gmlock/4.test_deadlock.go @@ -6,17 +6,18 @@ import ( "sync" "time" - "github.com/gogf/gf/os/gmlock" + "github.com/gogf/gf/v2/os/gmlock" ) // 测试Locker是否会产生死锁 func main() { - l := gmlock.New() - wg := sync.WaitGroup{} - key := "test" - event := make(chan int) - number := 100000 - + var ( + l = gmlock.New() + wg = sync.WaitGroup{} + key = "test" + event = make(chan int) + number = 100000 + ) for i := 0; i < number; i++ { wg.Add(1) go func() { diff --git a/.example/os/gmlock/locker2.go b/.example/os/gmlock/locker2.go deleted file mode 100644 index f340a25c9..000000000 --- a/.example/os/gmlock/locker2.go +++ /dev/null @@ -1,23 +0,0 @@ -package main - -import ( - "sync" - - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gmlock" -) - -// 内存锁 - 给定过期时间 -func main() { - key := "lock" - wg := sync.WaitGroup{} - for i := 0; i < 10; i++ { - wg.Add(1) - go func(i int) { - gmlock.Lock(key, 1000) - glog.Println(i) - wg.Done() - }(i) - } - wg.Wait() -} diff --git a/.example/os/gmlock/test_mutex.go b/.example/os/gmlock/test_mutex.go deleted file mode 100644 index c03874e70..000000000 --- a/.example/os/gmlock/test_mutex.go +++ /dev/null @@ -1,95 +0,0 @@ -package main - -import ( - "fmt" - "math/rand" - "sync" - "time" - - "github.com/gogf/gf/os/gmlock" -) - -// 测试是否会产生死锁 -func main() { - mu := gmlock.NewMutex() - wg := sync.WaitGroup{} - event := make(chan int) - number := 100000 - - for i := 0; i < number; i++ { - wg.Add(1) - go func() { - <-event - mu.Lock() - //fmt.Println("get lock") - mu.Unlock() - wg.Done() - }() - } - - for i := 0; i < number; i++ { - wg.Add(1) - go func() { - <-event - mu.RLock() - //fmt.Println("get rlock") - mu.RUnlock() - wg.Done() - }() - } - - for i := 0; i < number; i++ { - wg.Add(1) - go func() { - <-event - if mu.TryLock() { - //fmt.Println("get lock") - mu.Unlock() - } - wg.Done() - }() - } - - for i := 0; i < number; i++ { - wg.Add(1) - go func() { - <-event - if mu.TryRLock() { - //fmt.Println("get rlock") - mu.RUnlock() - } - wg.Done() - }() - } - - for i := 0; i < number; i++ { - wg.Add(1) - go func() { - <-event - if mu.TryLock() { - // 模拟业务逻辑的随机处理间隔 - time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond) - mu.Unlock() - } - wg.Done() - }() - } - - for i := 0; i < number; i++ { - wg.Add(1) - go func() { - <-event - if mu.TryRLock() { - // 模拟业务逻辑的随机处理间隔 - time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond) - mu.RUnlock() - } - wg.Done() - }() - } - // 使用chan作为事件发送测试指令,让所有的goroutine同时执行 - close(event) - wg.Wait() - - fmt.Println("done!") -} diff --git a/.example/os/gmutex/gmutex_basic.go b/.example/os/gmutex/gmutex_basic.go index e89bbcd3d..5ca0944fa 100644 --- a/.example/os/gmutex/gmutex_basic.go +++ b/.example/os/gmutex/gmutex_basic.go @@ -3,8 +3,8 @@ package main import ( "time" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gmutex" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gmutex" ) func main() { @@ -13,7 +13,7 @@ func main() { go func(n int) { mu.Lock() defer mu.Unlock() - glog.Println("Lock:", n) + glog.Print("Lock:", n) time.Sleep(time.Second) }(i) } @@ -21,7 +21,7 @@ func main() { go func(n int) { mu.RLock() defer mu.RUnlock() - glog.Println("RLock:", n) + glog.Print("RLock:", n) time.Sleep(time.Second) }(i) } diff --git a/.example/os/gmutex/gmutex_func.go b/.example/os/gmutex/gmutex_func.go index b26308736..cc2515883 100644 --- a/.example/os/gmutex/gmutex_func.go +++ b/.example/os/gmutex/gmutex_func.go @@ -3,20 +3,20 @@ package main import ( "time" - "github.com/gogf/gf/os/glog" + "github.com/gogf/gf/v2/os/glog" - "github.com/gogf/gf/os/gmutex" + "github.com/gogf/gf/v2/os/gmutex" ) func main() { mu := gmutex.New() go mu.LockFunc(func() { - glog.Println("lock func1") + glog.Print("lock func1") time.Sleep(1 * time.Second) }) time.Sleep(time.Millisecond) go mu.LockFunc(func() { - glog.Println("lock func2") + glog.Print("lock func2") }) time.Sleep(2 * time.Second) } diff --git a/.example/os/gproc/gproc.go b/.example/os/gproc/gproc.go index f3629e82c..743f45979 100644 --- a/.example/os/gproc/gproc.go +++ b/.example/os/gproc/gproc.go @@ -4,8 +4,8 @@ import ( "os" "time" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gproc" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gproc" ) // 父子进程基本演示 diff --git a/.example/os/gproc/gproc3.go b/.example/os/gproc/gproc3.go index 0d1202227..49acaa0e0 100644 --- a/.example/os/gproc/gproc3.go +++ b/.example/os/gproc/gproc3.go @@ -4,8 +4,8 @@ import ( "os" "time" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gproc" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gproc" ) // 父进程销毁后,使用进程管理器查看存活的子进程。 diff --git a/.example/os/gproc/gproc4.go b/.example/os/gproc/gproc4.go index 2b7caeb75..2fd2855fd 100644 --- a/.example/os/gproc/gproc4.go +++ b/.example/os/gproc/gproc4.go @@ -4,9 +4,9 @@ import ( "os" "time" - "github.com/gogf/gf/os/genv" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gproc" + "github.com/gogf/gf/v2/os/genv" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gproc" ) // 查看父子进程的环境变量 diff --git a/.example/os/gproc/gproc_comm.go b/.example/os/gproc/gproc_comm.go index 858cbf4c6..ca95ee290 100644 --- a/.example/os/gproc/gproc_comm.go +++ b/.example/os/gproc/gproc_comm.go @@ -5,10 +5,10 @@ import ( "os" "time" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gproc" - "github.com/gogf/gf/os/gtime" - "github.com/gogf/gf/os/gtimer" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gproc" + "github.com/gogf/gf/v2/os/gtime" + "github.com/gogf/gf/v2/os/gtimer" ) func main() { diff --git a/.example/os/gproc/gproc_comm_group.go b/.example/os/gproc/gproc_comm_group.go index 13191ed74..90e216944 100644 --- a/.example/os/gproc/gproc_comm_group.go +++ b/.example/os/gproc/gproc_comm_group.go @@ -6,8 +6,8 @@ import ( "os" "time" - "github.com/gogf/gf/os/gproc" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/os/gproc" + "github.com/gogf/gf/v2/os/gtime" ) func main() { diff --git a/.example/os/gproc/gproc_comm_send.go b/.example/os/gproc/gproc_comm_send.go index c29b2cf35..a3f6c92b5 100644 --- a/.example/os/gproc/gproc_comm_send.go +++ b/.example/os/gproc/gproc_comm_send.go @@ -4,7 +4,7 @@ package main import ( "fmt" - "github.com/gogf/gf/os/gproc" + "github.com/gogf/gf/v2/os/gproc" ) func main() { diff --git a/.example/os/gproc/gproc_kill.go b/.example/os/gproc/gproc_kill.go index 978c0deda..cb438e0f3 100644 --- a/.example/os/gproc/gproc_kill.go +++ b/.example/os/gproc/gproc_kill.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "github.com/gogf/gf/os/gproc" + "github.com/gogf/gf/v2/os/gproc" ) func main() { diff --git a/.example/os/gproc/gproc_shellexec.go b/.example/os/gproc/gproc_shellexec.go index 7ba255193..ed6600839 100644 --- a/.example/os/gproc/gproc_shellexec.go +++ b/.example/os/gproc/gproc_shellexec.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/os/gproc" + "github.com/gogf/gf/v2/os/gproc" ) // 执行shell指令 diff --git a/.example/os/gproc/gproc_sleep.go b/.example/os/gproc/gproc_sleep.go index 35162ac56..66aaadea2 100644 --- a/.example/os/gproc/gproc_sleep.go +++ b/.example/os/gproc/gproc_sleep.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "github.com/gogf/gf/os/gproc" + "github.com/gogf/gf/v2/os/gproc" ) func main() { diff --git a/.example/os/gproc/signal/signal_handler.go b/.example/os/gproc/signal/signal_handler.go new file mode 100644 index 000000000..a1d495347 --- /dev/null +++ b/.example/os/gproc/signal/signal_handler.go @@ -0,0 +1,54 @@ +package main + +import ( + "fmt" + "os" + "os/signal" + "syscall" + "time" +) + +func signalHandlerForMQ() { + var ( + sig os.Signal + receivedChan = make(chan os.Signal) + ) + signal.Notify( + receivedChan, + syscall.SIGINT, + syscall.SIGQUIT, + syscall.SIGKILL, + syscall.SIGTERM, + syscall.SIGABRT, + ) + for { + sig = <-receivedChan + fmt.Println("MQ is shutting down due to signal:", sig.String()) + time.Sleep(time.Second) + fmt.Println("MQ is shut down smoothly") + return + } +} + +func main() { + fmt.Println("Process start, pid:", os.Getpid()) + go signalHandlerForMQ() + + var ( + sig os.Signal + receivedChan = make(chan os.Signal) + ) + signal.Notify( + receivedChan, + syscall.SIGINT, + syscall.SIGQUIT, + syscall.SIGKILL, + syscall.SIGTERM, + syscall.SIGABRT, + ) + for { + sig = <-receivedChan + fmt.Println("MainProcess is shutting down due to signal:", sig.String()) + return + } +} diff --git a/.example/os/gproc/signal/signal_handler_gproc.go b/.example/os/gproc/signal/signal_handler_gproc.go new file mode 100644 index 000000000..06cde3386 --- /dev/null +++ b/.example/os/gproc/signal/signal_handler_gproc.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/gogf/gf/v2/os/gproc" + "os" + "time" +) + +func signalHandlerForMQ(sig os.Signal) { + fmt.Println("MQ is shutting down due to signal:", sig.String()) + time.Sleep(time.Second) + fmt.Println("MQ is shut down smoothly") +} + +func signalHandlerForMain(sig os.Signal) { + fmt.Println("MainProcess is shutting down due to signal:", sig.String()) +} + +func main() { + fmt.Println("Process start, pid:", os.Getpid()) + gproc.AddSigHandlerShutdown( + signalHandlerForMQ, + signalHandlerForMain, + ) + gproc.Listen() +} diff --git a/.example/os/gres/gres_example.go b/.example/os/gres/gres_example.go index c2d62108c..cf2084107 100644 --- a/.example/os/gres/gres_example.go +++ b/.example/os/gres/gres_example.go @@ -1,10 +1,10 @@ package main import ( - _ "github.com/gogf/gf/os/gres/testdata/example/boot" + _ "github.com/gogf/gf/v2/os/gres/testdata/example/boot" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/os/gres/gres_pack.go b/.example/os/gres/gres_pack.go index d9382c9d3..28c6e237e 100644 --- a/.example/os/gres/gres_pack.go +++ b/.example/os/gres/gres_pack.go @@ -1,9 +1,9 @@ package main import ( - "github.com/gogf/gf/crypto/gaes" - "github.com/gogf/gf/os/gfile" - "github.com/gogf/gf/os/gres" + "github.com/gogf/gf/v2/crypto/gaes" + "github.com/gogf/gf/v2/os/gfile" + "github.com/gogf/gf/v2/os/gres" ) var ( diff --git a/.example/os/gres/gres_unpack.go b/.example/os/gres/gres_unpack.go index 734065052..cec200e3b 100644 --- a/.example/os/gres/gres_unpack.go +++ b/.example/os/gres/gres_unpack.go @@ -1,9 +1,9 @@ package main import ( - "github.com/gogf/gf/crypto/gaes" - "github.com/gogf/gf/os/gfile" - "github.com/gogf/gf/os/gres" + "github.com/gogf/gf/v2/crypto/gaes" + "github.com/gogf/gf/v2/os/gfile" + "github.com/gogf/gf/v2/os/gres" ) var ( diff --git a/.example/os/grpool/goroutine.go b/.example/os/grpool/goroutine.go index fc97f88e5..2bbcc1468 100644 --- a/.example/os/grpool/goroutine.go +++ b/.example/os/grpool/goroutine.go @@ -5,7 +5,7 @@ import ( "sync" "time" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/os/gtime" ) func main() { diff --git a/.example/os/grpool/grpool.go b/.example/os/grpool/grpool.go index e067af081..9e02a0952 100644 --- a/.example/os/grpool/grpool.go +++ b/.example/os/grpool/grpool.go @@ -5,8 +5,8 @@ import ( "sync" "time" - "github.com/gogf/gf/os/grpool" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/os/grpool" + "github.com/gogf/gf/v2/os/gtime" ) func main() { diff --git a/.example/os/grpool/grpool1.go b/.example/os/grpool/grpool1.go index 311e6a0de..a71a1d0b2 100644 --- a/.example/os/grpool/grpool1.go +++ b/.example/os/grpool/grpool1.go @@ -4,8 +4,8 @@ import ( "fmt" "time" - "github.com/gogf/gf/os/grpool" - "github.com/gogf/gf/os/gtimer" + "github.com/gogf/gf/v2/os/grpool" + "github.com/gogf/gf/v2/os/gtimer" ) func job() { diff --git a/.example/os/grpool/grpool2.go b/.example/os/grpool/grpool2.go index 1494763f5..4cb3933dc 100644 --- a/.example/os/grpool/grpool2.go +++ b/.example/os/grpool/grpool2.go @@ -4,7 +4,7 @@ import ( "fmt" "sync" - "github.com/gogf/gf/os/grpool" + "github.com/gogf/gf/v2/os/grpool" ) func main() { diff --git a/.example/os/grpool/grpool3.go b/.example/os/grpool/grpool3.go index c7738000a..a91e14641 100644 --- a/.example/os/grpool/grpool3.go +++ b/.example/os/grpool/grpool3.go @@ -4,7 +4,7 @@ import ( "fmt" "sync" - "github.com/gogf/gf/os/grpool" + "github.com/gogf/gf/v2/os/grpool" ) func main() { diff --git a/.example/os/grpool/grpool5.go b/.example/os/grpool/grpool5.go index 7f6b7e2d6..0b9c1aeff 100644 --- a/.example/os/grpool/grpool5.go +++ b/.example/os/grpool/grpool5.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/gogf/gf/os/grpool" + "github.com/gogf/gf/v2/os/grpool" ) func main() { diff --git a/.example/os/gsession/storage-file/file.go b/.example/os/gsession/storage-file/file.go index 83cb57510..513ddf0d3 100644 --- a/.example/os/gsession/storage-file/file.go +++ b/.example/os/gsession/storage-file/file.go @@ -1,9 +1,9 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/gtime" "time" ) diff --git a/.example/os/gsession/storage-memory/memory.go b/.example/os/gsession/storage-memory/memory.go index 8d956c989..13821122f 100644 --- a/.example/os/gsession/storage-memory/memory.go +++ b/.example/os/gsession/storage-memory/memory.go @@ -1,10 +1,10 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/os/gsession" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/gsession" + "github.com/gogf/gf/v2/os/gtime" "time" ) diff --git a/.example/os/gsession/storage-redis-hashtable/redis-hashtable.go b/.example/os/gsession/storage-redis-hashtable/redis-hashtable.go index 2e35f89ca..4a83c8793 100644 --- a/.example/os/gsession/storage-redis-hashtable/redis-hashtable.go +++ b/.example/os/gsession/storage-redis-hashtable/redis-hashtable.go @@ -1,10 +1,10 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/os/gsession" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/gsession" + "github.com/gogf/gf/v2/os/gtime" "time" ) diff --git a/.example/os/gsession/storage-redis/redis.go b/.example/os/gsession/storage-redis/redis.go index 9dbcc4a4d..5b7068c3e 100644 --- a/.example/os/gsession/storage-redis/redis.go +++ b/.example/os/gsession/storage-redis/redis.go @@ -1,10 +1,10 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/os/gsession" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/gsession" + "github.com/gogf/gf/v2/os/gtime" "time" ) diff --git a/.example/os/gspath/gspath.go b/.example/os/gspath/gspath.go index 494ae5893..8e3eccc5d 100644 --- a/.example/os/gspath/gspath.go +++ b/.example/os/gspath/gspath.go @@ -4,9 +4,9 @@ import ( "fmt" "time" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/os/gspath" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gspath" + "github.com/gogf/gf/v2/os/gtime" ) func main() { diff --git a/.example/os/gtime/gtime_format.go b/.example/os/gtime/gtime_format.go index 636fd682e..b0bdc9322 100644 --- a/.example/os/gtime/gtime_format.go +++ b/.example/os/gtime/gtime_format.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/os/gtime" ) func main() { diff --git a/.example/os/gtime/gtime_func.go b/.example/os/gtime/gtime_func.go index a7e75aaeb..d362ac25e 100644 --- a/.example/os/gtime/gtime_func.go +++ b/.example/os/gtime/gtime_func.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/os/gtime" ) func main() { diff --git a/.example/os/gtime/gtime_json.go b/.example/os/gtime/gtime_json.go index 08770df9e..66209af74 100644 --- a/.example/os/gtime/gtime_json.go +++ b/.example/os/gtime/gtime_json.go @@ -4,7 +4,7 @@ import ( "encoding/json" "fmt" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/os/gtime" ) func main() { diff --git a/.example/os/gtime/gtime_layout.go b/.example/os/gtime/gtime_layout.go index adada9892..a75f0b90d 100644 --- a/.example/os/gtime/gtime_layout.go +++ b/.example/os/gtime/gtime_layout.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/os/gtime" ) func main() { diff --git a/.example/os/gtime/gtime_linkop.go b/.example/os/gtime/gtime_linkop.go index 33323cfdf..d708bffc9 100644 --- a/.example/os/gtime/gtime_linkop.go +++ b/.example/os/gtime/gtime_linkop.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/os/gtime" ) func main() { diff --git a/.example/os/gtime/gtime_parsertime.go b/.example/os/gtime/gtime_parsertime.go index 6f928f34c..740df565b 100644 --- a/.example/os/gtime/gtime_parsertime.go +++ b/.example/os/gtime/gtime_parsertime.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/os/gtime" ) func main() { diff --git a/.example/os/gtime/gtime_regex1.go b/.example/os/gtime/gtime_regex1.go index 0f7bfe48f..4f0826af9 100644 --- a/.example/os/gtime/gtime_regex1.go +++ b/.example/os/gtime/gtime_regex1.go @@ -4,7 +4,7 @@ import ( "fmt" "regexp" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/os/gtime" ) func main() { diff --git a/.example/os/gtime/gtime_regex2.go b/.example/os/gtime/gtime_regex2.go index 434aaa306..99c07859e 100644 --- a/.example/os/gtime/gtime_regex2.go +++ b/.example/os/gtime/gtime_regex2.go @@ -4,7 +4,7 @@ import ( "fmt" "regexp" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/os/gtime" ) func main() { diff --git a/.example/os/gtime/gtime_strtotime.go b/.example/os/gtime/gtime_strtotime.go index 3f73a4159..4169e66f2 100644 --- a/.example/os/gtime/gtime_strtotime.go +++ b/.example/os/gtime/gtime_strtotime.go @@ -1,11 +1,12 @@ package main import ( + "context" "fmt" "time" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gtime" ) func main() { @@ -38,7 +39,7 @@ func main() { fmt.Println(t.UTC().String()) fmt.Println(t.In(cstLocal).String()) } else { - glog.Error(s, err) + glog.Error(context.Background(), s, err) } fmt.Println() } diff --git a/.example/os/gtime/gtime_strtotime2.go b/.example/os/gtime/gtime_strtotime2.go index df05d10fb..7b3e0e86f 100644 --- a/.example/os/gtime/gtime_strtotime2.go +++ b/.example/os/gtime/gtime_strtotime2.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/os/gtime" ) func main() { diff --git a/.example/os/gtime/gtime_zone.go b/.example/os/gtime/gtime_zone.go index 11fe03f99..e34c5f988 100644 --- a/.example/os/gtime/gtime_zone.go +++ b/.example/os/gtime/gtime_zone.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/os/gtime" ) func main() { diff --git a/.example/os/gtimer/gtimer-batch.go b/.example/os/gtimer/gtimer-batch.go index 4152ba7f8..cbc902ef8 100644 --- a/.example/os/gtimer/gtimer-batch.go +++ b/.example/os/gtimer/gtimer-batch.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/gogf/gf/os/gtimer" + "github.com/gogf/gf/v2/os/gtimer" ) func main() { diff --git a/.example/os/gtimer/gtimer1.go b/.example/os/gtimer/gtimer1.go index 9a4a63e3b..1f965f6ea 100644 --- a/.example/os/gtimer/gtimer1.go +++ b/.example/os/gtimer/gtimer1.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/gogf/gf/os/gtimer" + "github.com/gogf/gf/v2/os/gtimer" ) func main() { diff --git a/.example/os/gtimer/gtimer2.go b/.example/os/gtimer/gtimer2.go index 8429a16b7..3844e6bd5 100644 --- a/.example/os/gtimer/gtimer2.go +++ b/.example/os/gtimer/gtimer2.go @@ -4,8 +4,8 @@ import ( "fmt" "time" - "github.com/gogf/gf/container/gtype" - "github.com/gogf/gf/os/gtimer" + "github.com/gogf/gf/v2/container/gtype" + "github.com/gogf/gf/v2/os/gtimer" ) func main() { diff --git a/.example/os/gtimer/gtimer3.go b/.example/os/gtimer/gtimer3.go index 6cf16e3d0..aa726c704 100644 --- a/.example/os/gtimer/gtimer3.go +++ b/.example/os/gtimer/gtimer3.go @@ -3,14 +3,14 @@ package main import ( "time" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gtimer" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gtimer" ) func main() { interval := time.Second gtimer.AddSingleton(interval, func() { - glog.Println("doing") + glog.Print("doing") time.Sleep(5 * time.Second) }) diff --git a/.example/os/gtimer/gtimer4.go b/.example/os/gtimer/gtimer4.go index 8d9cc6491..88dea15bf 100644 --- a/.example/os/gtimer/gtimer4.go +++ b/.example/os/gtimer/gtimer4.go @@ -3,17 +3,17 @@ package main import ( "time" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gtimer" + "github.com/gogf/gf/v2/os/glog" + "github.com/gogf/gf/v2/os/gtimer" ) func main() { interval := time.Second gtimer.AddTimes(interval, 2, func() { - glog.Println("doing1") + glog.Print("doing1") }) gtimer.AddTimes(interval, 2, func() { - glog.Println("doing2") + glog.Print("doing2") }) select {} diff --git a/.example/os/gview/assign/assign.go b/.example/os/gview/assign/assign.go index 1f64a5b6c..af0389af6 100644 --- a/.example/os/gview/assign/assign.go +++ b/.example/os/gview/assign/assign.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/os/gview" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gview" ) func main() { diff --git a/.example/os/gview/basic/gview.go b/.example/os/gview/basic/gview.go index d4e15ea40..53b31222c 100644 --- a/.example/os/gview/basic/gview.go +++ b/.example/os/gview/basic/gview.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { diff --git a/.example/os/gview/bind_func/gview_func1.go b/.example/os/gview/bind_func/gview_func1.go index fa6f3c873..bbbe8cb33 100644 --- a/.example/os/gview/bind_func/gview_func1.go +++ b/.example/os/gview/bind_func/gview_func1.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/os/gview" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gview" ) // 用于测试的内置函数 diff --git a/.example/os/gview/bind_func/gview_func2.go b/.example/os/gview/bind_func/gview_func2.go index 3ecda6c20..ca711b6a3 100644 --- a/.example/os/gview/bind_func/gview_func2.go +++ b/.example/os/gview/bind_func/gview_func2.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) // 用于测试的带参数的内置函数 diff --git a/.example/os/gview/build_in_funcs/build_in_funcs1.go b/.example/os/gview/build_in_funcs/build_in_funcs1.go index 7fdb59f5c..3f365ec83 100644 --- a/.example/os/gview/build_in_funcs/build_in_funcs1.go +++ b/.example/os/gview/build_in_funcs/build_in_funcs1.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { diff --git a/.example/os/gview/build_in_funcs/build_in_funcs2.go b/.example/os/gview/build_in_funcs/build_in_funcs2.go index ec1a213bc..9fc8c34ee 100644 --- a/.example/os/gview/build_in_funcs/build_in_funcs2.go +++ b/.example/os/gview/build_in_funcs/build_in_funcs2.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { diff --git a/.example/os/gview/build_in_funcs/issue359-1.go b/.example/os/gview/build_in_funcs/issue359-1.go index e43fd267b..842910e4d 100644 --- a/.example/os/gview/build_in_funcs/issue359-1.go +++ b/.example/os/gview/build_in_funcs/issue359-1.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { diff --git a/.example/os/gview/build_in_funcs/issue359-2.go b/.example/os/gview/build_in_funcs/issue359-2.go index 14d6a6940..f05041bee 100644 --- a/.example/os/gview/build_in_funcs/issue359-2.go +++ b/.example/os/gview/build_in_funcs/issue359-2.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { diff --git a/.example/os/gview/define/main.go b/.example/os/gview/define/main.go index 233da7347..95a9c87b7 100644 --- a/.example/os/gview/define/main.go +++ b/.example/os/gview/define/main.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/os/gfile" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gfile" ) func main() { diff --git a/.example/os/gview/delimiters/gview_delimiters.go b/.example/os/gview/delimiters/gview_delimiters.go index deec2c873..139c198d6 100644 --- a/.example/os/gview/delimiters/gview_delimiters.go +++ b/.example/os/gview/delimiters/gview_delimiters.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { diff --git a/.example/os/gview/func_html/func_html.go b/.example/os/gview/func_html/func_html.go index 0e41ec1e8..0f75aa607 100644 --- a/.example/os/gview/func_html/func_html.go +++ b/.example/os/gview/func_html/func_html.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/os/gview" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gview" ) func main() { diff --git a/.example/os/gview/func_text/func_text.go b/.example/os/gview/func_text/func_text.go index fae721814..390df9cbc 100644 --- a/.example/os/gview/func_text/func_text.go +++ b/.example/os/gview/func_text/func_text.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/os/gview" - "github.com/gogf/gf/util/gutil" + "github.com/gogf/gf/v2/os/gview" + "github.com/gogf/gf/v2/util/gutil" ) func main() { diff --git a/.example/os/gview/hot_update/controller_hot_update.go b/.example/os/gview/hot_update/controller_hot_update.go index 9475efe0e..e3734482c 100644 --- a/.example/os/gview/hot_update/controller_hot_update.go +++ b/.example/os/gview/hot_update/controller_hot_update.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/frame/gmvc" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/frame/gmvc" ) func init() { diff --git a/.example/os/gview/hot_update/gview_hot_update.go b/.example/os/gview/hot_update/gview_hot_update.go index 1982d2805..70b7f1415 100644 --- a/.example/os/gview/hot_update/gview_hot_update.go +++ b/.example/os/gview/hot_update/gview_hot_update.go @@ -4,8 +4,8 @@ import ( "fmt" "time" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/os/gtime" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gtime" ) func main() { diff --git a/.example/os/gview/hot_update/web_hot_update.go b/.example/os/gview/hot_update/web_hot_update.go index caa57ca1e..31aab9192 100644 --- a/.example/os/gview/hot_update/web_hot_update.go +++ b/.example/os/gview/hot_update/web_hot_update.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/os/gview/i18n/i18n.go b/.example/os/gview/i18n/i18n.go index b5a575244..c6fa628db 100644 --- a/.example/os/gview/i18n/i18n.go +++ b/.example/os/gview/i18n/i18n.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) func main() { diff --git a/.example/os/gview/include/main.go b/.example/os/gview/include/main.go index 425d23326..0fdd1d642 100644 --- a/.example/os/gview/include/main.go +++ b/.example/os/gview/include/main.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/os/gfile" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gfile" ) func main() { diff --git a/.example/os/gview/layout/layout1/main.go b/.example/os/gview/layout/layout1/main.go index ed12906bc..644e59568 100644 --- a/.example/os/gview/layout/layout1/main.go +++ b/.example/os/gview/layout/layout1/main.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/os/gview/layout/layout2/main.go b/.example/os/gview/layout/layout2/main.go index f90ae6fc1..5f7d8779f 100644 --- a/.example/os/gview/layout/layout2/main.go +++ b/.example/os/gview/layout/layout2/main.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" ) func main() { diff --git a/.example/os/gview/object/object.go b/.example/os/gview/object/object.go index b71f6f8f8..594a41ab2 100644 --- a/.example/os/gview/object/object.go +++ b/.example/os/gview/object/object.go @@ -1,7 +1,7 @@ package main import ( - "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/v2/frame/g" ) type T struct { diff --git a/.example/os/gview/resource/main1.go b/.example/os/gview/resource/main1.go index e0cab5a15..88b96590e 100644 --- a/.example/os/gview/resource/main1.go +++ b/.example/os/gview/resource/main1.go @@ -3,9 +3,9 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/os/gres" - _ "github.com/gogf/gf/os/gres/testdata" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gres" + _ "github.com/gogf/gf/v2/os/gres/testdata" ) func main() { diff --git a/.example/os/gview/resource/main2.go b/.example/os/gview/resource/main2.go index 2e18dc4d0..9892c4fc8 100644 --- a/.example/os/gview/resource/main2.go +++ b/.example/os/gview/resource/main2.go @@ -3,9 +3,9 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/os/gres" - _ "github.com/gogf/gf/os/gres/testdata" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gres" + _ "github.com/gogf/gf/v2/os/gres/testdata" ) func main() { diff --git a/.example/os/gview/resource/main3.go b/.example/os/gview/resource/main3.go index ad3dbfa1d..db3e029ed 100644 --- a/.example/os/gview/resource/main3.go +++ b/.example/os/gview/resource/main3.go @@ -3,9 +3,9 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/os/gres" - _ "github.com/gogf/gf/os/gres/testdata" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gres" + _ "github.com/gogf/gf/v2/os/gres/testdata" ) func main() { diff --git a/.example/text/gregex/gregex.go b/.example/text/gregex/gregex.go index 496588af1..5c807daa8 100644 --- a/.example/text/gregex/gregex.go +++ b/.example/text/gregex/gregex.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/text/gregex" + "github.com/gogf/gf/v2/text/gregex" ) func main() { diff --git a/.example/text/gstr/gstr_hidestr.go b/.example/text/gstr/gstr_hidestr.go index ca3808afb..1b7e9b268 100644 --- a/.example/text/gstr/gstr_hidestr.go +++ b/.example/text/gstr/gstr_hidestr.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/text/gstr" + "github.com/gogf/gf/v2/text/gstr" ) func main() { diff --git a/.example/text/gstr/gstr_substr.go b/.example/text/gstr/gstr_substr.go index c78d46700..75898a51e 100644 --- a/.example/text/gstr/gstr_substr.go +++ b/.example/text/gstr/gstr_substr.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/text/gstr" + "github.com/gogf/gf/v2/text/gstr" ) func main() { diff --git a/.example/util/gconv/gconv.go b/.example/util/gconv/gconv.go index 20811c713..1f148d906 100644 --- a/.example/util/gconv/gconv.go +++ b/.example/util/gconv/gconv.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/util/gconv" ) func main() { diff --git a/.example/util/gconv/gconv_map1.go b/.example/util/gconv/gconv_map1.go index 17a1b2d3f..e1ca4658a 100644 --- a/.example/util/gconv/gconv_map1.go +++ b/.example/util/gconv/gconv_map1.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/util/gconv" ) func main() { diff --git a/.example/util/gconv/gconv_map2.go b/.example/util/gconv/gconv_map2.go index 55b8c7048..52a3c4564 100644 --- a/.example/util/gconv/gconv_map2.go +++ b/.example/util/gconv/gconv_map2.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/util/gconv" ) func main() { diff --git a/.example/util/gconv/gconv_map_deep.go b/.example/util/gconv/gconv_map_deep.go index 9ce95323c..80a2a82ce 100644 --- a/.example/util/gconv/gconv_map_deep.go +++ b/.example/util/gconv/gconv_map_deep.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/util/gconv" ) func main() { diff --git a/.example/util/gconv/gconv_map_tag.go b/.example/util/gconv/gconv_map_tag.go index c11de8cec..727f4bf83 100644 --- a/.example/util/gconv/gconv_map_tag.go +++ b/.example/util/gconv/gconv_map_tag.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/util/gconv" ) func main() { diff --git a/.example/util/gconv/gconv_slice.go b/.example/util/gconv/gconv_slice.go index b6409ec52..c306e2cac 100644 --- a/.example/util/gconv/gconv_slice.go +++ b/.example/util/gconv/gconv_slice.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/util/gconv" ) // struct转slice diff --git a/.example/util/gconv/gconv_struct1.go b/.example/util/gconv/gconv_struct1.go index 35d888230..1cd680b5d 100644 --- a/.example/util/gconv/gconv_struct1.go +++ b/.example/util/gconv/gconv_struct1.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/util/gconv" ) type User struct { diff --git a/.example/util/gconv/gconv_struct2.go b/.example/util/gconv/gconv_struct2.go index ed6d182a7..5d09c723b 100644 --- a/.example/util/gconv/gconv_struct2.go +++ b/.example/util/gconv/gconv_struct2.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/util/gconv" ) // 使用默认映射规则绑定属性值到对象 diff --git a/.example/util/gconv/gconv_struct4.go b/.example/util/gconv/gconv_struct4.go index 73e46c222..c9dba3445 100644 --- a/.example/util/gconv/gconv_struct4.go +++ b/.example/util/gconv/gconv_struct4.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/util/gconv" ) func main() { diff --git a/.example/util/gconv/gconv_struct5.go b/.example/util/gconv/gconv_struct5.go index 6882e7cba..2351653a7 100644 --- a/.example/util/gconv/gconv_struct5.go +++ b/.example/util/gconv/gconv_struct5.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/util/gconv" ) func main() { diff --git a/.example/util/gconv/gconv_struct6.go b/.example/util/gconv/gconv_struct6.go index 14c29b42e..a7681a0e1 100644 --- a/.example/util/gconv/gconv_struct6.go +++ b/.example/util/gconv/gconv_struct6.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/util/gconv" ) func main() { diff --git a/.example/util/gconv/gconv_struct_create.go b/.example/util/gconv/gconv_struct_create.go index 7c6352c2e..211cfea46 100644 --- a/.example/util/gconv/gconv_struct_create.go +++ b/.example/util/gconv/gconv_struct_create.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/util/gconv" ) func main() { diff --git a/.example/util/gconv/gconv_struct_deep.go b/.example/util/gconv/gconv_struct_deep.go index 15b47c60f..565766321 100644 --- a/.example/util/gconv/gconv_struct_deep.go +++ b/.example/util/gconv/gconv_struct_deep.go @@ -1,8 +1,8 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/util/gconv" ) func main() { diff --git a/.example/util/gconv/strings.go b/.example/util/gconv/strings.go index bd8b95933..258d6d638 100644 --- a/.example/util/gconv/strings.go +++ b/.example/util/gconv/strings.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/util/gconv" ) func main() { diff --git a/.example/util/gconv/time1.go b/.example/util/gconv/time1.go index b9aab0c82..825d49f5f 100644 --- a/.example/util/gconv/time1.go +++ b/.example/util/gconv/time1.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/util/gconv" ) func main() { diff --git a/.example/util/gconv/time2.go b/.example/util/gconv/time2.go index f3e054b57..c7d77a406 100644 --- a/.example/util/gconv/time2.go +++ b/.example/util/gconv/time2.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/gogf/gf/util/gconv" + "github.com/gogf/gf/v2/util/gconv" ) func main() { diff --git a/.example/util/gpage/gpage.go b/.example/util/gpage/gpage.go index 00f80ee7a..cc39411aa 100644 --- a/.example/util/gpage/gpage.go +++ b/.example/util/gpage/gpage.go @@ -1,9 +1,9 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/os/gview" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/gview" ) func main() { diff --git a/.example/util/gpage/gpage_ajax.go b/.example/util/gpage/gpage_ajax.go index a33a83cdc..5451472a1 100644 --- a/.example/util/gpage/gpage_ajax.go +++ b/.example/util/gpage/gpage_ajax.go @@ -1,9 +1,9 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/os/gview" + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/ghttp" + "github.com/gogf/gf/v2/os/gview" ) func main() { @@ -11,7 +11,7 @@ func main() { s.BindHandler("/page/ajax", func(r *ghttp.Request) { page := r.GetPage(100, 10) page.AjaxActionName = "DoAjax" - buffer, _ := gview.ParseContent(` + buffer, _ := gview.ParseContent(r.Context(), `