make singleton thread safe

This commit is contained in:
saga92
2016-05-24 09:41:34 +08:00
parent 2f60bf4f1f
commit de51b247f7
+4 -2
View File
@@ -22,6 +22,7 @@ import (
"os"
"strings"
"sync"
"time"
"github.com/astaxie/beego/orm"
@@ -99,11 +100,12 @@ func InitDB() {
}
var globalOrm orm.Ormer
var once sync.Once
// GetOrmer :set ormer singleton
func GetOrmer() orm.Ormer {
if globalOrm == nil {
once.Do(func() {
globalOrm = orm.NewOrm()
}
})
return globalOrm
}