dbr/util.go

24 lines
488 B
Go

package dbr
// NameMapping is the routine to use when mapping column names to struct properties
var NameMapping = camelCaseToSnakeCase
func camelCaseToSnakeCase(name string) string {
var newstr []rune
firstTime := true
for _, chr := range name {
if isUpper := 'A' <= chr && chr <= 'Z'; isUpper {
if firstTime == true {
firstTime = false
} else {
newstr = append(newstr, '_')
}
chr -= ('A' - 'a')
}
newstr = append(newstr, chr)
}
return string(newstr)
}