2020-01-31 07:22:37 +03:00
|
|
|
package schema
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
2020-02-01 13:02:19 +03:00
|
|
|
"regexp"
|
2020-01-31 07:22:37 +03:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2020-02-01 15:18:25 +03:00
|
|
|
func ParseTagSetting(tags reflect.StructTag) map[string]string {
|
2020-01-31 07:22:37 +03:00
|
|
|
setting := map[string]string{}
|
|
|
|
|
|
|
|
for _, value := range strings.Split(tags.Get("gorm"), ";") {
|
|
|
|
if value != "" {
|
|
|
|
v := strings.Split(value, ":")
|
|
|
|
k := strings.TrimSpace(strings.ToUpper(v[0]))
|
|
|
|
|
|
|
|
if len(v) >= 2 {
|
|
|
|
setting[k] = strings.Join(v[1:], ":")
|
|
|
|
} else {
|
|
|
|
setting[k] = k
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return setting
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkTruth(val string) bool {
|
|
|
|
if strings.ToLower(val) == "false" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2020-02-01 07:46:52 +03:00
|
|
|
|
|
|
|
func toColumns(val string) (results []string) {
|
|
|
|
if val != "" {
|
|
|
|
for _, v := range strings.Split(val, ",") {
|
|
|
|
results = append(results, strings.TrimSpace(v))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2020-02-01 13:02:19 +03:00
|
|
|
|
|
|
|
func removeSettingFromTag(tag reflect.StructTag, name string) reflect.StructTag {
|
|
|
|
return reflect.StructTag(regexp.MustCompile(`(?i)(gorm:.*?)(`+name+`:.*?)(;|("))`).ReplaceAllString(string(tag), "${1}${4}"))
|
|
|
|
}
|