Skip to content

Commit f63747e

Browse files
committed
Merge branch 'master' of https://github.com/gogf/gf
2 parents 2854dad + 6ff4ed8 commit f63747e

File tree

129 files changed

+7517
-2535
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+7517
-2535
lines changed

.github/workflows/gf.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
services:
3838
# Redis backend server.
3939
redis:
40-
image : loads/redis:latest
40+
image : loads/redis:7.0
4141
options: >-
4242
--health-cmd "redis-cli ping"
4343
--health-interval 10s
@@ -77,7 +77,7 @@ jobs:
7777
7878
# MSSQL backend server.
7979
mssql:
80-
image: loads/mssqldocker:latest
80+
image: loads/mssqldocker:14.0.3391.2
8181
env:
8282
ACCEPT_EULA: Y
8383
SA_PASSWORD: LoremIpsum86
@@ -94,25 +94,25 @@ jobs:
9494
--health-retries 10
9595
9696
# ClickHouse backend server.
97-
# docker run -d --name clickhouse -p 9000:9000 -p 8123:8123 -p 9001:9001 loads/clickhouse-server:latest
97+
# docker run -d --name clickhouse -p 9000:9000 -p 8123:8123 -p 9001:9001 loads/clickhouse-server:22.1.3.7
9898
clickhouse-server:
99-
image: loads/clickhouse-server:latest
99+
image: loads/clickhouse-server:22.1.3.7
100100
ports:
101101
- 9000:9000
102102
- 8123:8123
103103
- 9001:9001
104104

105105
# Polaris backend server.
106106
polaris:
107-
image: loads/polaris-server-standalone:latest
107+
image: loads/polaris-server-standalone:1.11.2
108108
ports:
109109
- 8090:8090
110110
- 8091:8091
111111
- 8093:8093
112112

113113
# Oracle 11g server
114114
oracle-server:
115-
image: loads/oracle-xe-11g-r2:latest
115+
image: loads/oracle-xe-11g-r2:11.2.0
116116
env:
117117
ORACLE_ALLOW_REMOTE: true
118118
ORACLE_SID: XE

cmd/gf/go.mod

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@ require (
1515

1616
require (
1717
github.com/BurntSushi/toml v1.2.1 // indirect
18-
github.com/cespare/xxhash/v2 v2.1.2 // indirect
1918
github.com/clbanning/mxj/v2 v2.5.5 // indirect
2019
github.com/denisenkom/go-mssqldb v0.11.0 // indirect
21-
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
2220
github.com/fatih/color v1.13.0 // indirect
2321
github.com/fsnotify/fsnotify v1.5.4 // indirect
2422
github.com/glebarez/go-sqlite v1.17.3 // indirect
2523
github.com/go-logr/logr v1.2.3 // indirect
2624
github.com/go-logr/stdr v1.2.2 // indirect
27-
github.com/go-redis/redis/v8 v8.11.5 // indirect
2825
github.com/go-sql-driver/mysql v1.6.0 // indirect
2926
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect
3027
github.com/google/uuid v1.3.0 // indirect

cmd/gf/go.sum

Lines changed: 1 addition & 74 deletions
Large diffs are not rendered by default.

cmd/gf/internal/cmd/cmd_fix.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type cFix struct {
2020

2121
type cFixInput struct {
2222
g.Meta `name:"fix"`
23+
Path string `name:"path" brief:"directory path, it uses current working directory in default"`
2324
}
2425

2526
type cFixOutput struct{}
@@ -32,12 +33,15 @@ type cFixItem struct {
3233
func (c cFix) Index(ctx context.Context, in cFixInput) (out *cFixOutput, err error) {
3334
mlog.Print(`start auto fixing...`)
3435
defer mlog.Print(`done!`)
35-
err = c.doFix()
36+
if in.Path == "" {
37+
in.Path = gfile.Pwd()
38+
}
39+
err = c.doFix(in)
3640
return
3741
}
3842

39-
func (c cFix) doFix() (err error) {
40-
version, err := c.getVersion()
43+
func (c cFix) doFix(in cFixInput) (err error) {
44+
version, err := c.getVersion(in)
4145
if err != nil {
4246
mlog.Fatal(err)
4347
}
@@ -68,16 +72,25 @@ func (c cFix) doFix() (err error) {
6872
// doFixV23 fixes code when upgrading to GoFrame v2.3.
6973
func (c cFix) doFixV23(version string) error {
7074
replaceFunc := func(path, content string) string {
75+
// gdb.TX from struct to interface.
7176
content = gstr.Replace(content, "*gdb.TX", "gdb.TX")
77+
// function name changes for package gtcp/gudp.
78+
if gstr.Contains(content, "/gf/v2/net/gtcp") || gstr.Contains(content, "/gf/v2/net/gudp") {
79+
content = gstr.ReplaceByMap(content, g.MapStrStr{
80+
".SetSendDeadline": ".SetDeadlineSend",
81+
".SetReceiveDeadline": ".SetDeadlineRecv",
82+
".SetReceiveBufferWait": ".SetBufferWaitRecv",
83+
})
84+
}
7285
return content
7386
}
7487
return gfile.ReplaceDirFunc(replaceFunc, ".", "*.go", true)
7588
}
7689

77-
func (c cFix) getVersion() (string, error) {
90+
func (c cFix) getVersion(in cFixInput) (string, error) {
7891
var (
7992
err error
80-
path = "go.mod"
93+
path = gfile.Join(in.Path, "go.mod")
8194
version string
8295
)
8396
if !gfile.Exists(path) {
@@ -86,7 +99,7 @@ func (c cFix) getVersion() (string, error) {
8699
err = gfile.ReadLines(path, func(line string) error {
87100
array := gstr.SplitAndTrim(line, " ")
88101
if len(array) > 0 {
89-
if array[0] == gfPackage {
102+
if gstr.HasPrefix(array[0], gfPackage) {
90103
version = array[1]
91104
}
92105
}

cmd/gf/internal/cmd/cmd_up.go

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type cUp struct {
2121
}
2222

2323
const (
24-
gfPackage = `github.com/gogf/gf/v2`
24+
gfPackage = `github.com/gogf/gf/`
2525
cUpEg = `
2626
gf up
2727
gf up -a
@@ -46,20 +46,19 @@ type cUpInput struct {
4646
type cUpOutput struct{}
4747

4848
func (c cUp) Index(ctx context.Context, in cUpInput) (out *cUpOutput, err error) {
49-
defer mlog.Print(`done!`)
49+
defer func() {
50+
if err == nil {
51+
mlog.Print(`done!`)
52+
}
53+
}()
5054

5155
if in.All {
5256
in.Cli = true
5357
in.Fix = true
5458
}
55-
if err = c.doUpgradeVersion(ctx); err != nil {
59+
if err = c.doUpgradeVersion(ctx, in); err != nil {
5660
return nil, err
5761
}
58-
if in.Fix {
59-
if err = c.doAutoFixing(ctx); err != nil {
60-
return nil, err
61-
}
62-
}
6362
//if in.Cli {
6463
// if err = c.doUpgradeCLI(ctx); err != nil {
6564
// return nil, err
@@ -68,34 +67,49 @@ func (c cUp) Index(ctx context.Context, in cUpInput) (out *cUpOutput, err error)
6867
return
6968
}
7069

71-
func (c cUp) doUpgradeVersion(ctx context.Context) (err error) {
70+
func (c cUp) doUpgradeVersion(ctx context.Context, in cUpInput) (err error) {
7271
mlog.Print(`start upgrading version...`)
7372

73+
type Package struct {
74+
Name string
75+
Version string
76+
}
77+
7478
var (
7579
dir = gfile.Pwd()
7680
temp string
7781
path = gfile.Join(dir, "go.mod")
7882
)
7983
for {
8084
if gfile.Exists(path) {
81-
var packages []string
85+
var packages []Package
8286
err = gfile.ReadLines(path, func(line string) error {
8387
line = gstr.Trim(line)
8488
if gstr.HasPrefix(line, gfPackage) {
85-
pkg := gstr.Explode(" ", line)[0]
86-
packages = append(packages, pkg)
89+
array := gstr.SplitAndTrim(line, " ")
90+
packages = append(packages, Package{
91+
Name: array[0],
92+
Version: array[1],
93+
})
8794
}
8895
return nil
8996
})
9097
if err != nil {
9198
return
9299
}
93100
for _, pkg := range packages {
94-
mlog.Printf(`upgrading %s`, pkg)
95-
command := fmt.Sprintf(`go get -u %s@latest`, pkg)
101+
mlog.Printf(`upgrading "%s" from "%s" to "latest"`, pkg.Name, pkg.Version)
102+
command := fmt.Sprintf(`go get -u %s@latest`, pkg.Name)
96103
if err = gproc.ShellRun(ctx, command); err != nil {
97104
return
98105
}
106+
mlog.Print()
107+
}
108+
if in.Fix {
109+
if err = c.doAutoFixing(ctx, dir); err != nil {
110+
return err
111+
}
112+
mlog.Print()
99113
}
100114
return
101115
}
@@ -110,12 +124,13 @@ func (c cUp) doUpgradeVersion(ctx context.Context) (err error) {
110124

111125
func (c cUp) doUpgradeCLI(ctx context.Context) (err error) {
112126
mlog.Print(`start upgrading cli...`)
113-
114127
return
115128
}
116129

117-
func (c cUp) doAutoFixing(ctx context.Context) (err error) {
118-
mlog.Print(`start auto fixing...`)
119-
err = cFix{}.doFix()
130+
func (c cUp) doAutoFixing(ctx context.Context, dirPath string) (err error) {
131+
mlog.Printf(`auto fixing path "%s"...`, dirPath)
132+
err = cFix{}.doFix(cFixInput{
133+
Path: dirPath,
134+
})
120135
return
121136
}

cmd/gf/internal/consts/consts_gen_dao_template_dao.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/gf/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ func main() {
6969
if err != nil {
7070
panic(err)
7171
}
72-
command.Run(ctx)
72+
err = command.RunWithError(ctx)
73+
if err != nil {
74+
panic(err)
75+
}
7376
}
7477

7578
// zsh alias "git fetch" conflicts checks.

container/gpool/gpool.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ func (p *Pool) Put(value interface{}) error {
8484
return nil
8585
}
8686

87+
// MustPut puts an item to pool, it panics if any error occurs.
88+
func (p *Pool) MustPut(value interface{}) {
89+
if err := p.Put(value); err != nil {
90+
panic(err)
91+
}
92+
}
93+
8794
// Clear clears pool, which means it will remove all items from pool.
8895
func (p *Pool) Clear() {
8996
if p.ExpireFunc != nil {

container/gpool/gpool_z_example_test.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func ExamplePool_Put() {
6161
// conn.(*DBConn).Conn.QueryContext(context.Background(), "select * from user")
6262

6363
// put back conn
64-
dbConnPool.Put(conn)
64+
dbConnPool.MustPut(conn)
6565

6666
fmt.Println(conn.(*DBConn).Limit)
6767

@@ -88,8 +88,8 @@ func ExamplePool_Clear() {
8888
})
8989

9090
conn, _ := dbConnPool.Get()
91-
dbConnPool.Put(conn)
92-
dbConnPool.Put(conn)
91+
dbConnPool.MustPut(conn)
92+
dbConnPool.MustPut(conn)
9393
fmt.Println(dbConnPool.Size())
9494
dbConnPool.Clear()
9595
fmt.Println(dbConnPool.Size())
@@ -144,8 +144,8 @@ func ExamplePool_Size() {
144144

145145
conn, _ := dbConnPool.Get()
146146
fmt.Println(dbConnPool.Size())
147-
dbConnPool.Put(conn)
148-
dbConnPool.Put(conn)
147+
dbConnPool.MustPut(conn)
148+
dbConnPool.MustPut(conn)
149149
fmt.Println(dbConnPool.Size())
150150

151151
// Output:
@@ -158,21 +158,22 @@ func ExamplePool_Close() {
158158
Conn *sql.Conn
159159
Limit int
160160
}
161-
162-
dbConnPool := gpool.New(time.Hour,
163-
func() (interface{}, error) {
161+
var (
162+
newFunc = func() (interface{}, error) {
164163
dbConn := new(DBConn)
165164
dbConn.Limit = 10
166165
return dbConn, nil
167-
},
168-
func(i interface{}) {
166+
}
167+
closeFunc = func(i interface{}) {
169168
fmt.Println("Close The Pool")
170169
// sample : close db conn
171170
// i.(DBConn).Conn.Close()
172-
})
171+
}
172+
)
173+
dbConnPool := gpool.New(time.Hour, newFunc, closeFunc)
173174

174175
conn, _ := dbConnPool.Get()
175-
dbConnPool.Put(conn)
176+
dbConnPool.MustPut(conn)
176177

177178
dbConnPool.Close()
178179

0 commit comments

Comments
 (0)