forked from asternic/wuzapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclients.go
More file actions
57 lines (47 loc) · 1.22 KB
/
Copy pathclients.go
File metadata and controls
57 lines (47 loc) · 1.22 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
package main
import (
"sync"
"github.com/go-resty/resty/v2"
"go.mau.fi/whatsmeow"
)
type ClientManager struct {
sync.RWMutex
whatsmeowClients map[string]*whatsmeow.Client
httpClients map[string]*resty.Client
}
func NewClientManager() *ClientManager {
return &ClientManager{
whatsmeowClients: make(map[string]*whatsmeow.Client),
httpClients: make(map[string]*resty.Client),
}
}
func (cm *ClientManager) SetWhatsmeowClient(userID string, client *whatsmeow.Client) {
cm.Lock()
defer cm.Unlock()
cm.whatsmeowClients[userID] = client
}
func (cm *ClientManager) GetWhatsmeowClient(userID string) *whatsmeow.Client {
cm.RLock()
defer cm.RUnlock()
return cm.whatsmeowClients[userID]
}
func (cm *ClientManager) DeleteWhatsmeowClient(userID string) {
cm.Lock()
defer cm.Unlock()
delete(cm.whatsmeowClients, userID)
}
func (cm *ClientManager) SetHTTPClient(userID string, client *resty.Client) {
cm.Lock()
defer cm.Unlock()
cm.httpClients[userID] = client
}
func (cm *ClientManager) GetHTTPClient(userID string) *resty.Client {
cm.RLock()
defer cm.RUnlock()
return cm.httpClients[userID]
}
func (cm *ClientManager) DeleteHTTPClient(userID string) {
cm.Lock()
defer cm.Unlock()
delete(cm.httpClients, userID)
}