1
0
mirror of https://github.com/gogf/gf.git synced 2025-04-05 03:05:05 +08:00

fix length check issue (#2725)

This commit is contained in:
John Guo 2023-07-04 09:49:09 +08:00 committed by GitHub
parent 3fab7a341d
commit 9620b15ea1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 11 deletions

View File

@ -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, "*")

View File

@ -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

View File

@ -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 {

View File

@ -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]
}
}

View File

@ -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]
}
}

View File

@ -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)