1
0
mirror of https://github.com/astaxie/beego.git synced 2024-12-23 18:40:49 +00:00

Merge pull request #608 from JessonChan/develop

refactor func
This commit is contained in:
astaxie 2014-05-14 20:47:01 +08:00
commit 9f95fd3309

View File

@ -16,7 +16,7 @@ import (
// register models. // register models.
// prefix means table name prefix. // prefix means table name prefix.
func registerModel(model interface{}, prefix string) { func registerModel(prefix string, model interface{}) {
val := reflect.ValueOf(model) val := reflect.ValueOf(model)
ind := reflect.Indirect(val) ind := reflect.Indirect(val)
typ := ind.Type() typ := ind.Type()
@ -292,23 +292,17 @@ end:
// register models // register models
func RegisterModel(models ...interface{}) { func RegisterModel(models ...interface{}) {
if modelCache.done { RegisterModelWithPrefix("", models)
panic(fmt.Errorf("RegisterModel must be run before BootStrap"))
} }
for _, model := range models { // register models with a prefix
registerModel(model, "")
}
}
// register model with a prefix
func RegisterModelWithPrefix(prefix string, models ...interface{}) { func RegisterModelWithPrefix(prefix string, models ...interface{}) {
if modelCache.done { if modelCache.done {
panic(fmt.Errorf("RegisterModel must be run before BootStrap")) panic(fmt.Errorf("RegisterModel must be run before BootStrap"))
} }
for _, model := range models { for _, model := range models {
registerModel(model, prefix) registerModel(prefix, model)
} }
} }