mirror of
https://github.com/gogf/gf.git
synced 2025-04-05 11:18:50 +08:00
fix length check issue (#2725)
This commit is contained in:
parent
3fab7a341d
commit
9620b15ea1
@ -68,7 +68,7 @@ func (c CGenService) calculateCodeCommented(in CGenServiceInput, fileContent str
|
|||||||
)
|
)
|
||||||
if len(receiverArray) > 1 {
|
if len(receiverArray) > 1 {
|
||||||
structName = receiverArray[1]
|
structName = receiverArray[1]
|
||||||
} else {
|
} else if len(receiverArray) == 1 {
|
||||||
structName = receiverArray[0]
|
structName = receiverArray[0]
|
||||||
}
|
}
|
||||||
structName = gstr.Trim(structName, "*")
|
structName = gstr.Trim(structName, "*")
|
||||||
@ -121,7 +121,7 @@ func (c CGenService) calculateInterfaceFunctions(
|
|||||||
)
|
)
|
||||||
if len(receiverArray) > 1 {
|
if len(receiverArray) > 1 {
|
||||||
structName = receiverArray[1]
|
structName = receiverArray[1]
|
||||||
} else {
|
} else if len(receiverArray) == 1 {
|
||||||
structName = receiverArray[0]
|
structName = receiverArray[0]
|
||||||
}
|
}
|
||||||
structName = gstr.Trim(structName, "*")
|
structName = gstr.Trim(structName, "*")
|
||||||
|
@ -55,7 +55,7 @@ func (m *Model) Data(data ...interface{}) *Model {
|
|||||||
}
|
}
|
||||||
model.data = m
|
model.data = m
|
||||||
}
|
}
|
||||||
} else {
|
} else if len(data) == 1 {
|
||||||
switch value := data[0].(type) {
|
switch value := data[0].(type) {
|
||||||
case Result:
|
case Result:
|
||||||
model.data = value.List()
|
model.data = value.List()
|
||||||
@ -151,10 +151,13 @@ func (m *Model) Data(data ...interface{}) *Model {
|
|||||||
// "nickname": "passport",
|
// "nickname": "passport",
|
||||||
// }).
|
// }).
|
||||||
func (m *Model) OnDuplicate(onDuplicate ...interface{}) *Model {
|
func (m *Model) OnDuplicate(onDuplicate ...interface{}) *Model {
|
||||||
|
if len(onDuplicate) == 0 {
|
||||||
|
return m
|
||||||
|
}
|
||||||
model := m.getModel()
|
model := m.getModel()
|
||||||
if len(onDuplicate) > 1 {
|
if len(onDuplicate) > 1 {
|
||||||
model.onDuplicate = onDuplicate
|
model.onDuplicate = onDuplicate
|
||||||
} else {
|
} else if len(onDuplicate) == 1 {
|
||||||
model.onDuplicate = onDuplicate[0]
|
model.onDuplicate = onDuplicate[0]
|
||||||
}
|
}
|
||||||
return model
|
return model
|
||||||
@ -173,10 +176,13 @@ func (m *Model) OnDuplicate(onDuplicate ...interface{}) *Model {
|
|||||||
// "password": "",
|
// "password": "",
|
||||||
// }).
|
// }).
|
||||||
func (m *Model) OnDuplicateEx(onDuplicateEx ...interface{}) *Model {
|
func (m *Model) OnDuplicateEx(onDuplicateEx ...interface{}) *Model {
|
||||||
|
if len(onDuplicateEx) == 0 {
|
||||||
|
return m
|
||||||
|
}
|
||||||
model := m.getModel()
|
model := m.getModel()
|
||||||
if len(onDuplicateEx) > 1 {
|
if len(onDuplicateEx) > 1 {
|
||||||
model.onDuplicateEx = onDuplicateEx
|
model.onDuplicateEx = onDuplicateEx
|
||||||
} else {
|
} else if len(onDuplicateEx) == 1 {
|
||||||
model.onDuplicateEx = onDuplicateEx[0]
|
model.onDuplicateEx = onDuplicateEx[0]
|
||||||
}
|
}
|
||||||
return model
|
return model
|
||||||
|
@ -219,7 +219,7 @@ func (m *Manager) init(ctx context.Context) {
|
|||||||
array = strings.Split(path, "/")
|
array = strings.Split(path, "/")
|
||||||
if len(array) > 1 {
|
if len(array) > 1 {
|
||||||
lang = array[0]
|
lang = array[0]
|
||||||
} else {
|
} else if len(array) == 1 {
|
||||||
lang = gfile.Name(array[0])
|
lang = gfile.Name(array[0])
|
||||||
}
|
}
|
||||||
if m.data[lang] == nil {
|
if m.data[lang] == nil {
|
||||||
@ -250,7 +250,7 @@ func (m *Manager) init(ctx context.Context) {
|
|||||||
array = strings.Split(path, gfile.Separator)
|
array = strings.Split(path, gfile.Separator)
|
||||||
if len(array) > 1 {
|
if len(array) > 1 {
|
||||||
lang = array[0]
|
lang = array[0]
|
||||||
} else {
|
} else if len(array) == 1 {
|
||||||
lang = gfile.Name(array[0])
|
lang = gfile.Name(array[0])
|
||||||
}
|
}
|
||||||
if m.data[lang] == nil {
|
if m.data[lang] == nil {
|
||||||
|
@ -82,7 +82,7 @@ func HeaderToMap(header http.Header) map[string]interface{} {
|
|||||||
for k, v := range header {
|
for k, v := range header {
|
||||||
if len(v) > 1 {
|
if len(v) > 1 {
|
||||||
m[k] = v
|
m[k] = v
|
||||||
} else {
|
} else if len(v) == 1 {
|
||||||
m[k] = v[0]
|
m[k] = v[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@ func (ct *clientTracer) tlsHandshakeDone(_ tls.ConnectionState, err error) {
|
|||||||
func (ct *clientTracer) wroteHeaderField(k string, v []string) {
|
func (ct *clientTracer) wroteHeaderField(k string, v []string) {
|
||||||
if len(v) > 1 {
|
if len(v) > 1 {
|
||||||
ct.headers[k] = v
|
ct.headers[k] = v
|
||||||
} else {
|
} else if len(v) == 1 {
|
||||||
ct.headers[k] = v[0]
|
ct.headers[k] = v[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.
|
// 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)
|
c.SetIfNotExist(ctx, "k1", 0, -10000)
|
||||||
|
|
||||||
// Wait 1 second for K1: V1 to expire automatically
|
// Wait 1.5 second for K1: V1 to expire automatically
|
||||||
time.Sleep(1200 * time.Millisecond)
|
time.Sleep(1500 * time.Millisecond)
|
||||||
|
|
||||||
// Print the current key value pair again and find that K1: V1 has expired
|
// Print the current key value pair again and find that K1: V1 has expired
|
||||||
keys2, _ := c.Keys(ctx)
|
keys2, _ := c.Keys(ctx)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user