-
Notifications
You must be signed in to change notification settings - Fork 1
/
service.go
88 lines (75 loc) · 1.87 KB
/
service.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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package service
import (
"github.com/0xor1/tlbx/pkg/email"
"github.com/0xor1/tlbx/pkg/fcm"
"github.com/0xor1/tlbx/pkg/iredis"
"github.com/0xor1/tlbx/pkg/sqlh"
"github.com/0xor1/tlbx/pkg/store"
"github.com/0xor1/tlbx/pkg/web/app"
emailmw "github.com/0xor1/tlbx/pkg/web/app/service/email"
fcmmw "github.com/0xor1/tlbx/pkg/web/app/service/fcm"
"github.com/0xor1/tlbx/pkg/web/app/service/redis"
"github.com/0xor1/tlbx/pkg/web/app/service/sql"
storemw "github.com/0xor1/tlbx/pkg/web/app/service/store"
)
const (
cache = "cache"
sqlUser = "user"
sqlPwd = "pwd"
sqlData = "data"
emailName = "email"
storeName = "store"
fcmName = "fcm"
)
type Layer interface {
Cache() redis.Pool
User() sql.Client
Pwd() sql.Client
Data() sql.Client
Email() email.Client
Store() store.Client
FCM() fcmmw.Client
}
func Mware(pool iredis.Pool, user, pwd, data sqlh.ReplicaSet, email email.Client, store store.Client, fcm fcm.Client) func(app.Tlbx) {
mwares := []func(app.Tlbx){
redis.Mware(cache, pool),
sql.Mware(sqlUser, user),
sql.Mware(sqlPwd, pwd),
sql.Mware(sqlData, data),
emailmw.Mware(emailName, email),
storemw.Mware(storeName, store),
fcmmw.Mware(sqlUser, fcmName, fcm),
}
return func(tlbx app.Tlbx) {
for _, mw := range mwares {
mw(tlbx)
}
}
}
type layer struct {
tlbx app.Tlbx
}
func Get(tlbx app.Tlbx) Layer {
return &layer{tlbx}
}
func (l *layer) Cache() redis.Pool {
return redis.Get(l.tlbx, cache)
}
func (l *layer) User() sql.Client {
return sql.Get(l.tlbx, sqlUser)
}
func (l *layer) Pwd() sql.Client {
return sql.Get(l.tlbx, sqlPwd)
}
func (l *layer) Data() sql.Client {
return sql.Get(l.tlbx, sqlData)
}
func (l *layer) Email() email.Client {
return emailmw.Get(l.tlbx, emailName)
}
func (l *layer) Store() store.Client {
return storemw.Get(l.tlbx, storeName)
}
func (l *layer) FCM() fcmmw.Client {
return fcmmw.Get(l.tlbx, fcmName)
}