-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient.go
More file actions
39 lines (32 loc) · 774 Bytes
/
client.go
File metadata and controls
39 lines (32 loc) · 774 Bytes
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
package dingtalk
import (
"sync"
"github.com/fromiuan/dingtalk/lib/cache"
)
type Client struct {
AppKey string // 企业内部应用appKey
AppSecret string // 企业内部应用appSecret
Debug bool
Cache cache.Cache
Tlock *sync.RWMutex
}
func NewClient(appkey, appsecret string) *Client {
cli := &Client{
AppKey: appkey,
AppSecret: appsecret,
Tlock: new(sync.RWMutex),
}
defaultCacheCfg := &cache.MemoryOpts{Interval: 1 * 60 * 60}
cacheAdapter, err := cache.NewCache("memory", defaultCacheCfg)
if err != nil {
panic("not find memory cache")
}
cli.Cache = cacheAdapter
return cli
}
func (c *Client) SetCache(key string, cfg interface{}) {
c.Cache, _ = cache.NewCache(key, cfg)
}
func (c *Client) SetDebug(b bool) {
c.Debug = b
}