Skip to content

Commit

Permalink
Merge branch 'master' of github.com:gogf/gf
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn committed Oct 8, 2024
2 parents fee6d02 + 7cbc9e8 commit 22773da
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions database/gdb/gdb_model_insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ func (m *Model) Data(data ...interface{}) *Model {
model.data = s
model.extraArgs = data[1:]
} else {
m := make(map[string]interface{})
newData := make(map[string]interface{})
for i := 0; i < len(data); i += 2 {
m[gconv.String(data[i])] = data[i+1]
newData[gconv.String(data[i])] = data[i+1]
}
model.data = m
model.data = newData
}
} else if len(data) == 1 {
switch value := data[0].(type) {
Expand Down
4 changes: 2 additions & 2 deletions os/gcache/gcache_z_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ func TestCache_LRU(t *testing.T) {
func TestCache_LRU_expire(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
cache := gcache.New(2)
t.Assert(cache.Set(ctx, 1, nil, time.Millisecond), nil)
t.Assert(cache.Set(ctx, 1, nil, 50*time.Millisecond), nil)

n, _ := cache.Size(ctx)
t.Assert(n, 1)

time.Sleep(time.Millisecond * 10)
time.Sleep(time.Millisecond * 100)

n, _ = cache.Size(ctx)
t.Assert(n, 0)
Expand Down
2 changes: 1 addition & 1 deletion util/gutil/gutil_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func GetOrDefaultStr(def string, param ...string) string {
// It returns `param[0]` if it is available, or else it returns `def`.
func GetOrDefaultAny(def interface{}, param ...interface{}) interface{} {
value := def
if len(param) > 0 && param[0] != "" {
if len(param) > 0 && param[0] != nil {
value = param[0]
}
return value
Expand Down
2 changes: 2 additions & 0 deletions util/gutil/gutil_z_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,5 +204,7 @@ func Test_GetOrDefaultAny(t *testing.T) {
t.Assert(gutil.GetOrDefaultAny("a", "b"), "b")
t.Assert(gutil.GetOrDefaultAny("a", "b", "c"), "b")
t.Assert(gutil.GetOrDefaultAny("a"), "a")
t.Assert(gutil.GetOrDefaultAny("a", nil), "a")
t.Assert(gutil.GetOrDefaultAny("a", ""), "")
})
}

0 comments on commit 22773da

Please sign in to comment.