-
Notifications
You must be signed in to change notification settings - Fork 0
/
standard.go
69 lines (60 loc) · 2 KB
/
standard.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
package glue
import (
"github.com/zhiyunliu/glue/cache"
"github.com/zhiyunliu/glue/circuitbreaker"
"github.com/zhiyunliu/glue/dlocker"
"github.com/zhiyunliu/glue/metrics"
"github.com/zhiyunliu/glue/queue"
"github.com/zhiyunliu/glue/ratelimit"
"github.com/zhiyunliu/glue/standard"
"github.com/zhiyunliu/glue/xdb"
"github.com/zhiyunliu/glue/xhttp"
"github.com/zhiyunliu/glue/xrpc"
)
// DB 获取DB 处理对象
func DB(name string, opts ...xdb.Option) xdb.IDB {
obj := standard.GetInstance(xdb.DbTypeNode)
return obj.(xdb.StandardDB).GetDB(name, opts...)
}
// Cache 获取Cache 处理对象
func Cache(name string, opts ...cache.Option) cache.ICache {
obj := standard.GetInstance(cache.TypeNode)
return obj.(cache.StandardCache).GetCache(name, opts...)
}
// Queue 获取Queue 处理对象
func Queue(name string, opts ...queue.Option) queue.IQueue {
obj := standard.GetInstance(queue.TypeNode)
return obj.(queue.StandardQueue).GetQueue(name, opts...)
}
// RPC 获取RPC 处理对象
func RPC(name string) xrpc.Client {
obj := standard.GetInstance(xrpc.TypeNode)
return obj.(xrpc.StandardRPC).GetRPC(name)
}
// Http 获取Http处理对象
func Http(name string) xhttp.Client {
obj := standard.GetInstance(xhttp.TypeNode)
return obj.(xhttp.StandardHttp).GetHttp(name)
}
// DLocker 获取DLocker 处理对象
func DLocker(key string, opts ...dlocker.Option) dlocker.DLocker {
obj := standard.GetInstance(dlocker.TypeNode)
return obj.(dlocker.StandardLocker).GetDLocker().Build(key, opts...)
}
// 暂时没考虑用泛型
func Custom(name string) interface{} {
obj := standard.GetInstance(name)
return obj
}
// 注册默认的提供程序
func init() {
standard.Registry(xdb.NewBuilder())
standard.Registry(cache.NewBuilder())
standard.Registry(queue.NewBuilder())
standard.Registry(xrpc.NewBuilder())
standard.Registry(xhttp.NewBuilder())
standard.Registry(dlocker.NewBuilder())
standard.Registry(metrics.NewBuilder())
standard.Registry(ratelimit.NewBuilder())
standard.Registry(circuitbreaker.NewBuilder())
}