diff --git a/cmd/gf/internal/cmd/genservice/genservice_calculate.go b/cmd/gf/internal/cmd/genservice/genservice_calculate.go index 46dc33172..68fe74618 100644 --- a/cmd/gf/internal/cmd/genservice/genservice_calculate.go +++ b/cmd/gf/internal/cmd/genservice/genservice_calculate.go @@ -68,7 +68,7 @@ func (c CGenService) calculateCodeCommented(in CGenServiceInput, fileContent str ) if len(receiverArray) > 1 { structName = receiverArray[1] - } else { + } else if len(receiverArray) == 1 { structName = receiverArray[0] } structName = gstr.Trim(structName, "*") @@ -121,7 +121,7 @@ func (c CGenService) calculateInterfaceFunctions( ) if len(receiverArray) > 1 { structName = receiverArray[1] - } else { + } else if len(receiverArray) == 1 { structName = receiverArray[0] } structName = gstr.Trim(structName, "*") diff --git a/database/gdb/gdb_model_insert.go b/database/gdb/gdb_model_insert.go index 3cde85328..131e3b3d9 100644 --- a/database/gdb/gdb_model_insert.go +++ b/database/gdb/gdb_model_insert.go @@ -55,7 +55,7 @@ func (m *Model) Data(data ...interface{}) *Model { } model.data = m } - } else { + } else if len(data) == 1 { switch value := data[0].(type) { case Result: model.data = value.List() @@ -151,10 +151,13 @@ func (m *Model) Data(data ...interface{}) *Model { // "nickname": "passport", // }). func (m *Model) OnDuplicate(onDuplicate ...interface{}) *Model { + if len(onDuplicate) == 0 { + return m + } model := m.getModel() if len(onDuplicate) > 1 { model.onDuplicate = onDuplicate - } else { + } else if len(onDuplicate) == 1 { model.onDuplicate = onDuplicate[0] } return model @@ -173,10 +176,13 @@ func (m *Model) OnDuplicate(onDuplicate ...interface{}) *Model { // "password": "", // }). func (m *Model) OnDuplicateEx(onDuplicateEx ...interface{}) *Model { + if len(onDuplicateEx) == 0 { + return m + } model := m.getModel() if len(onDuplicateEx) > 1 { model.onDuplicateEx = onDuplicateEx - } else { + } else if len(onDuplicateEx) == 1 { model.onDuplicateEx = onDuplicateEx[0] } return model diff --git a/i18n/gi18n/gi18n_manager.go b/i18n/gi18n/gi18n_manager.go index ad2b101b0..f22d1a2ce 100644 --- a/i18n/gi18n/gi18n_manager.go +++ b/i18n/gi18n/gi18n_manager.go @@ -219,7 +219,7 @@ func (m *Manager) init(ctx context.Context) { array = strings.Split(path, "/") if len(array) > 1 { lang = array[0] - } else { + } else if len(array) == 1 { lang = gfile.Name(array[0]) } if m.data[lang] == nil { @@ -250,7 +250,7 @@ func (m *Manager) init(ctx context.Context) { array = strings.Split(path, gfile.Separator) if len(array) > 1 { lang = array[0] - } else { + } else if len(array) == 1 { lang = gfile.Name(array[0]) } if m.data[lang] == nil { diff --git a/internal/httputil/httputils.go b/internal/httputil/httputils.go index 5fc9bb6f8..f006f3945 100644 --- a/internal/httputil/httputils.go +++ b/internal/httputil/httputils.go @@ -82,7 +82,7 @@ func HeaderToMap(header http.Header) map[string]interface{} { for k, v := range header { if len(v) > 1 { m[k] = v - } else { + } else if len(v) == 1 { m[k] = v[0] } } diff --git a/net/gclient/gclient_tracing_tracer.go b/net/gclient/gclient_tracing_tracer.go index c2e9ccbdc..8d48b742a 100644 --- a/net/gclient/gclient_tracing_tracer.go +++ b/net/gclient/gclient_tracing_tracer.go @@ -141,7 +141,7 @@ func (ct *clientTracer) tlsHandshakeDone(_ tls.ConnectionState, err error) { func (ct *clientTracer) wroteHeaderField(k string, v []string) { if len(v) > 1 { ct.headers[k] = v - } else { + } else if len(v) == 1 { ct.headers[k] = v[0] } } diff --git a/os/gcache/gcache_z_example_cache_test.go b/os/gcache/gcache_z_example_cache_test.go index eb599b191..7b249f773 100644 --- a/os/gcache/gcache_z_example_cache_test.go +++ b/os/gcache/gcache_z_example_cache_test.go @@ -86,8 +86,8 @@ func ExampleCache_SetIfNotExist() { // It does not expire if `duration` == 0. It deletes the `key` if `duration` < 0 or given `value` is nil. c.SetIfNotExist(ctx, "k1", 0, -10000) - // Wait 1 second for K1: V1 to expire automatically - time.Sleep(1200 * time.Millisecond) + // Wait 1.5 second for K1: V1 to expire automatically + time.Sleep(1500 * time.Millisecond) // Print the current key value pair again and find that K1: V1 has expired keys2, _ := c.Keys(ctx)