mirror of https://github.com/go-gorm/gorm.git
53 lines
973 B
Go
53 lines
973 B
Go
package gorm
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
|
|
"strings"
|
|
)
|
|
|
|
func toSnake(s string) string {
|
|
buf := bytes.NewBufferString("")
|
|
for i, v := range s {
|
|
if i > 0 && v >= 'A' && v <= 'Z' {
|
|
buf.WriteRune('_')
|
|
}
|
|
buf.WriteRune(v)
|
|
}
|
|
return strings.ToLower(buf.String())
|
|
}
|
|
|
|
func snakeToUpperCamel(s string) string {
|
|
buf := bytes.NewBufferString("")
|
|
for _, v := range strings.Split(s, "_") {
|
|
if len(v) > 0 {
|
|
buf.WriteString(strings.ToUpper(v[:1]))
|
|
buf.WriteString(v[1:])
|
|
}
|
|
}
|
|
return buf.String()
|
|
}
|
|
|
|
func toSearchableMap(attrs ...interface{}) (result interface{}) {
|
|
if len(attrs) > 1 {
|
|
if str, ok := attrs[0].(string); ok {
|
|
result = map[string]interface{}{str: attrs[1]}
|
|
}
|
|
} else if len(attrs) == 1 {
|
|
if attr, ok := attrs[0].(map[string]interface{}); ok {
|
|
result = attr
|
|
}
|
|
|
|
if attr, ok := attrs[0].(interface{}); ok {
|
|
result = attr
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func debug(value interface{}) {
|
|
fmt.Printf("***************\n")
|
|
fmt.Printf("%+v\n\n", value)
|
|
}
|