Created
July 1, 2018 13:12
-
-
Save jirfag/5fe94eab8c6746ebd9a8b5411e65f52a to your computer and use it in GitHub Desktop.
Issue found by nakedret linter in Beego
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (d *dbBase) collectValues(mi *modelInfo, ind reflect.Value, cols []string, skipAuto bool, insert bool, names *[]string, tz *time.Location) (values []interface{}, autoFields []string, err error) { | |
if names == nil { | |
ns := make([]string, 0, len(cols)) | |
names = &ns | |
} | |
values = make([]interface{}, 0, len(cols)) | |
for _, column := range cols { | |
var fi *fieldInfo | |
if fi, _ = mi.fields.GetByAny(column); fi != nil { | |
column = fi.column | |
} else { | |
panic(fmt.Errorf("wrong db field/column name `%s` for model `%s`", column, mi.fullName)) | |
} | |
if !fi.dbcol || fi.auto && skipAuto { | |
continue | |
} | |
value, err := d.collectFieldValue(mi, fi, ind, insert, tz) | |
if err != nil { | |
return nil, nil, err | |
} | |
// ignore empty value auto field | |
if insert && fi.auto { | |
if fi.fieldType&IsPositiveIntegerField > 0 { | |
if vu, ok := value.(uint64); !ok || vu == 0 { | |
continue | |
} | |
} else { | |
if vu, ok := value.(int64); !ok || vu == 0 { | |
continue | |
} | |
} | |
autoFields = append(autoFields, fi.column) | |
} | |
*names, values = append(*names, column), append(values, value) | |
} | |
return // Nakedret warns about this naked return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment