push_app_info_repository.go
1.7 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package repository
import (
"github.com/astaxie/beego/orm"
"openapi/pkg/domain"
"openapi/pkg/infrastructure/bgorm/model"
"sync"
)
var Cache sync.Map
type AppInfoRepository struct {
}
func (repository *AppInfoRepository) FindOne(queryOptions map[string]interface{}) (*domain.AppInfo, error) {
o := orm.NewOrm()
model := new(models.PushAppInfo)
var appInfo *domain.AppInfo
//var ok bool
var err error
//if appInfo, ok = getCache(queryOptions["project_id"]); ok {
// return appInfo, nil
//}
qs := o.QueryTable(model).Filter("project_id", queryOptions["project_id"])
err = qs.One(model)
if err != nil {
return nil, err
}
appInfo, err = repository.transformBgormModelToDomainModel(model)
//setCache(queryOptions["project_id"], appInfo)
return appInfo, err
}
func (repository *AppInfoRepository) Find(queryOptions map[string]interface{}) (rsp []*domain.AppInfo, err error) {
return
}
func (repository *AppInfoRepository) transformBgormModelToDomainModel(model *models.PushAppInfo) (*domain.AppInfo, error) {
return &domain.AppInfo{
Id: model.Id,
AppKey: model.AppKey,
AppMasterSecret: model.AppMasterSecret,
AppId: model.AppId,
ProjectId: model.ProjectId,
}, nil
}
func NewAppInfoRepository(transactionContext interface{}) (*AppInfoRepository, error) {
if transactionContext == nil {
return &AppInfoRepository{}, nil
} else {
return &AppInfoRepository{}, nil
}
}
//设置缓存
func setCache(key interface{}, value interface{}) {
Cache.Store(key, value)
}
//设置缓存
func getCache(key interface{}) (*domain.AppInfo, bool) {
v, ok := Cache.Load(key)
if !ok {
return nil, false
}
if appInfo, ok := v.(*domain.AppInfo); ok {
return appInfo, true
}
return nil, false
}