-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.go
68 lines (56 loc) · 1.25 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package rest
import (
"github.com/cloudwego/hertz/pkg/common/errors"
"github.com/nats-io/nats.go"
"github.com/redis/go-redis/v9"
"github.com/weplanx/go/cipher"
"github.com/weplanx/go/values"
"go.mongodb.org/mongo-driver/mongo"
)
func New(options ...Option) *Service {
x := new(Service)
for _, v := range options {
v(x)
}
return x
}
type Option func(x *Service)
func SetMongoClient(v *mongo.Client) Option {
return func(x *Service) {
x.Mgo = v
}
}
func SetDatabase(v *mongo.Database) Option {
return func(x *Service) {
x.Db = v
}
}
func SetRedis(v *redis.Client) Option {
return func(x *Service) {
x.RDb = v
}
}
func SetJetStream(v nats.JetStreamContext) Option {
return func(x *Service) {
x.JetStream = v
}
}
func SetKeyValue(v nats.KeyValue) Option {
return func(x *Service) {
x.KeyValue = v
}
}
func SetDynamicValues(v *values.DynamicValues) Option {
return func(x *Service) {
x.Values = v
}
}
func SetCipher(v *cipher.Cipher) Option {
return func(x *Service) {
x.Cipher = v
}
}
type M = map[string]interface{}
var ErrCollectionForbidden = errors.NewPublic("the collection is forbidden")
var ErrTxnNotExist = errors.NewPublic("the txn does not exist")
var ErrTxnTimeOut = errors.NewPublic("the transaction has timed out")