From aa091cea42a1ce1d227e149ecb66ba46ffda4f40 Mon Sep 17 00:00:00 2001 From: astaxie Date: Tue, 30 Aug 2016 22:02:11 +0800 Subject: [PATCH] improvement the error if use &&Struct --- orm/models.go | 10 +++++----- orm/models_boot.go | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/orm/models.go b/orm/models.go index faf551be..5cfc69b1 100644 --- a/orm/models.go +++ b/orm/models.go @@ -57,11 +57,11 @@ var ( // model info collection type _modelCache struct { - sync.RWMutex - orders []string - cache map[string]*modelInfo - cacheByFN map[string]*modelInfo - done bool + sync.RWMutex // only used outsite for bootStrap + orders []string + cache map[string]*modelInfo + cacheByFN map[string]*modelInfo + done bool } // get all model info diff --git a/orm/models_boot.go b/orm/models_boot.go index c9905330..364b68e9 100644 --- a/orm/models_boot.go +++ b/orm/models_boot.go @@ -32,6 +32,9 @@ func registerModel(prefix string, model interface{}) { if val.Kind() != reflect.Ptr { panic(fmt.Errorf(" cannot use non-ptr model struct `%s`", getFullName(typ))) } + if typ.Kind() == reflect.Ptr { + panic(fmt.Errorf(" only allow ptr model struct, it looks you use two reference to the struct `%s`", typ)) + } table := getTableName(val) @@ -320,7 +323,6 @@ func BootStrap() { if modelCache.done { return } - modelCache.Lock() defer modelCache.Unlock() bootStrap()