Skip to content

Commit

Permalink
Merge branch 'master' into fix/gogf#2746
Browse files Browse the repository at this point in the history
  • Loading branch information
oldme-git authored Feb 28, 2024
2 parents 2f163ae + 39a88ef commit 621089f
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 16 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ cmd/gf/gf
temp/
go.work
go.work.sum
!cmd/gf/go.work
!cmd/gf/go.work

# Ignore for docs
node_modules
.docusaurus
output
24 changes: 19 additions & 5 deletions cmd/gf/internal/cmd/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func (c cRun) Index(ctx context.Context, in cRunInput) (out *cRunOutput, err err

if len(in.WatchPaths) == 1 {
in.WatchPaths = strings.Split(in.WatchPaths[0], ",")
mlog.Printf("watchPaths: %v", in.WatchPaths)
}

app := &cRunApp{
Expand All @@ -109,8 +110,9 @@ func (c cRun) Index(ctx context.Context, in cRunInput) (out *cRunOutput, err err
WatchPaths: in.WatchPaths,
}
dirty := gtype.NewBool()
_, err = gfsnotify.Add(gfile.RealPath("."), func(event *gfsnotify.Event) {
if gfile.ExtName(event.Path) != "go" && !matchWatchPaths(app.WatchPaths, event.Path) {

callbackFunc := func(event *gfsnotify.Event) {
if gfile.ExtName(event.Path) != "go" {
return
}

Expand All @@ -125,10 +127,22 @@ func (c cRun) Index(ctx context.Context, in cRunInput) (out *cRunOutput, err err
mlog.Printf(`watched file changes: %s`, event.String())
app.Run(ctx)
})
})
if err != nil {
mlog.Fatal(err)
}

if len(app.WatchPaths) > 0 {
for _, path := range app.WatchPaths {
_, err = gfsnotify.Add(gfile.RealPath(path), callbackFunc)
if err != nil {
mlog.Fatal(err)
}
}
} else {
_, err = gfsnotify.Add(gfile.RealPath("."), callbackFunc)
if err != nil {
mlog.Fatal(err)
}
}

go app.Run(ctx)
select {}
}
Expand Down
2 changes: 1 addition & 1 deletion container/gpool/gpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Pool struct {
closed *gtype.Bool // Whether the pool is closed.
TTL time.Duration // Time To Live for pool items.
NewFunc func() (interface{}, error) // Callback function to create pool item.
// ExpireFunc is the for expired items destruction.
// ExpireFunc is the function for expired items destruction.
// This function needs to be defined when the pool items
// need to perform additional destruction operations.
// Eg: net.Conn, os.File, etc.
Expand Down
40 changes: 38 additions & 2 deletions contrib/drivers/mysql/mysql_z_unit_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3646,7 +3646,7 @@ func Test_Model_OnDuplicate(t *testing.T) {
table := createInitTable()
defer dropTable(table)

// string.
// string type 1.
gtest.C(t, func(t *gtest.T) {
data := g.Map{
"id": 1,
Expand All @@ -3664,6 +3664,24 @@ func Test_Model_OnDuplicate(t *testing.T) {
t.Assert(one["nickname"], "name_1")
})

// string type 2.
gtest.C(t, func(t *gtest.T) {
data := g.Map{
"id": 1,
"passport": "pp1",
"password": "pw1",
"nickname": "n1",
"create_time": "2016-06-06",
}
_, err := db.Model(table).OnDuplicate("passport", "password").Data(data).Save()
t.AssertNil(err)
one, err := db.Model(table).WherePri(1).One()
t.AssertNil(err)
t.Assert(one["passport"], data["passport"])
t.Assert(one["password"], data["password"])
t.Assert(one["nickname"], "name_1")
})

// slice.
gtest.C(t, func(t *gtest.T) {
data := g.Map{
Expand Down Expand Up @@ -3729,7 +3747,7 @@ func Test_Model_OnDuplicateEx(t *testing.T) {
table := createInitTable()
defer dropTable(table)

// string.
// string type 1.
gtest.C(t, func(t *gtest.T) {
data := g.Map{
"id": 1,
Expand All @@ -3747,6 +3765,24 @@ func Test_Model_OnDuplicateEx(t *testing.T) {
t.Assert(one["nickname"], "name_1")
})

// string type 2.
gtest.C(t, func(t *gtest.T) {
data := g.Map{
"id": 1,
"passport": "pp1",
"password": "pw1",
"nickname": "n1",
"create_time": "2016-06-06",
}
_, err := db.Model(table).OnDuplicateEx("nickname", "create_time").Data(data).Save()
t.AssertNil(err)
one, err := db.Model(table).WherePri(1).One()
t.AssertNil(err)
t.Assert(one["passport"], data["passport"])
t.Assert(one["password"], data["password"])
t.Assert(one["nickname"], "name_1")
})

// slice.
gtest.C(t, func(t *gtest.T) {
data := g.Map{
Expand Down
16 changes: 9 additions & 7 deletions contrib/drivers/oracle/oracle_open.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ package oracle

import (
"database/sql"
"strings"

gora "github.com/sijms/go-ora/v2"

"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/text/gregex"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gconv"
)

Expand Down Expand Up @@ -45,12 +46,13 @@ func (d *Driver) Open(config *gdb.ConfigNode) (db *sql.DB, err error) {
}
} else {
if config.Extra != "" {
var extraMap map[string]interface{}
if extraMap, err = gstr.Parse(config.Extra); err != nil {
return nil, err
}
for k, v := range extraMap {
options[k] = gconv.String(v)
// fix #3226
list := strings.Split(config.Extra, "&")
for _, v := range list {
kv := strings.Split(v, "=")
if len(kv) == 2 {
options[kv[0]] = kv[1]
}
}
}
source = gora.BuildUrl(
Expand Down
20 changes: 20 additions & 0 deletions contrib/drivers/oracle/oracle_z_unit_basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"
"testing"

"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/util/gconv"

"github.com/gogf/gf/v2/frame/g"
Expand Down Expand Up @@ -692,3 +693,22 @@ func Test_Empty_Slice_Argument(t *testing.T) {
t.Assert(len(result), 0)
})
}

// fix #3226
func Test_Extra(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
nodeLink := gdb.ConfigNode{
Type: TestDbType,
Name: TestDbName,
Link: fmt.Sprintf("%s:%s:%s@tcp(%s:%s)/%s?lob fetch=post&SSL VERIFY=false",
TestDbType, TestDbUser, TestDbPass, TestDbIP, TestDbPort, TestDbName,
),
}
if r, err := gdb.New(nodeLink); err != nil {
gtest.Fatal(err)
} else {
err1 := r.PingMaster()
t.Assert(err1, nil)
}
})
}
17 changes: 17 additions & 0 deletions os/gcache/gcache_z_example_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,23 @@ func ExampleCache_Removes() {
// map[k4:v4]
}

func ExampleCache_Clear() {
// Create a cache object,
// Of course, you can also easily use the gcache package method directly
c := gcache.New()

c.SetMap(ctx, g.MapAnyAny{"k1": "v1", "k2": "v2", "k3": "v3", "k4": "v4"}, 0)

// clears all data of the cache.
c.Clear(ctx)

data, _ := c.Data(ctx)
fmt.Println(data)

// Output:
// map[]
}

func ExampleCache_MustGet() {
// Intercepting panic exception information
// err is empty, so panic is not performed
Expand Down

0 comments on commit 621089f

Please sign in to comment.