-
Notifications
You must be signed in to change notification settings - Fork 3
/
env.go
87 lines (68 loc) · 1.46 KB
/
env.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
package env
import (
"sync"
"go.uber.org/zap"
"github.com/aliyun/aliyun-tablestore-go-sdk/v5/tablestore"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
)
type InfluxDBClient struct {
client *influxdb2.Client
}
type OSSClient struct {
EndPoint string
Bucket string
PathPrefix string
Client *oss.Client
}
type TablestoreClient struct {
TableName string
Client *tablestore.TableStoreClient
}
type Logger struct {
*zap.Logger
}
type Env struct {
logger *Logger
ossClient *OSSClient
tableStoreClient *TablestoreClient
influxClient *InfluxDBClient
}
var (
once sync.Once
env *Env
)
func Instance() *Env {
once.Do(func() {
env = &Env{
ossClient: &OSSClient{},
influxClient: &InfluxDBClient{},
tableStoreClient: &TablestoreClient{},
}
})
return env
}
func (e *Env) SetOSSClient(client *OSSClient) {
e.ossClient = client
}
func (e *Env) SetLogger(logger *Logger) {
e.logger = logger
}
func (e *Env) Logger() *Logger {
return e.logger
}
func (e *Env) OSSClient() *OSSClient {
return e.ossClient
}
func (e *Env) SetInfluxDBClient(client *influxdb2.Client) {
e.influxClient.client = client
}
func (e *Env) InfluxDBClient() *influxdb2.Client {
return e.influxClient.client
}
func (e *Env) SetTablestoreClient(client *TablestoreClient) {
e.tableStoreClient = client
}
func (e *Env) TablestoreClient() *TablestoreClient {
return e.tableStoreClient
}