forked from ccfos/nightingale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
44 lines (34 loc) · 770 Bytes
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package models
import (
"github.com/toolkits/pkg/str"
"gorm.io/gorm"
"github.com/didi/nightingale/v5/src/storage"
)
const AdminRole = "Admin"
func DB() *gorm.DB {
return storage.DB
}
func Count(tx *gorm.DB) (int64, error) {
var cnt int64
err := tx.Count(&cnt).Error
return cnt, err
}
func Exists(tx *gorm.DB) (bool, error) {
num, err := Count(tx)
return num > 0, err
}
func Insert(obj interface{}) error {
return DB().Create(obj).Error
}
// CryptoPass crypto password use salt
func CryptoPass(raw string) (string, error) {
salt, err := ConfigsGet("salt")
if err != nil {
return "", err
}
return str.MD5(salt + "<-*Uk30^96eY*->" + raw), nil
}
type Statistics struct {
Total int64 `gorm:"total"`
LastUpdated int64 `gorm:"last_updated"`
}