12
This commit is contained in:
26
internal/global/global.go
Normal file
26
internal/global/global.go
Normal file
@ -0,0 +1,26 @@
|
||||
package global
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"unR2/internal/config"
|
||||
"unR2/internal/ent"
|
||||
)
|
||||
|
||||
var (
|
||||
dbOnce sync.Once
|
||||
db *ent.Client
|
||||
AppConfig = &config.Conf
|
||||
)
|
||||
|
||||
func SetDB(client *ent.Client) {
|
||||
dbOnce.Do(func() {
|
||||
db = client
|
||||
})
|
||||
}
|
||||
|
||||
func DB() *ent.Client {
|
||||
if db == nil {
|
||||
panic("DB is not initialized")
|
||||
}
|
||||
return db
|
||||
}
|
||||
Reference in New Issue
Block a user