-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware.go
79 lines (60 loc) · 1.55 KB
/
middleware.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
// Package larkgin is gin middleware for go-lark/lark
package larkgin
import (
"github.com/go-lark/lark"
)
// DefaultLarkMessageKey compat legacy versions
// not use in this repo right now
const DefaultLarkMessageKey = "go-lark-message"
const (
defaultLarkMessageKey = "go-lark-message"
defaultLarkCardKey = "go-lark-card"
)
// LarkMiddleware .
type LarkMiddleware struct {
logger lark.LogWrapper
messageKey string
cardKey string
enableTokenVerification bool
verificationToken string
enableEncryption bool
encryptKey []byte
enableURLBinding bool
urlPrefix string
}
// NewLarkMiddleware .
func NewLarkMiddleware() *LarkMiddleware {
return &LarkMiddleware{
logger: initDefaultLogger(),
messageKey: defaultLarkMessageKey,
cardKey: defaultLarkCardKey,
}
}
// WithTokenVerification .
func (opt *LarkMiddleware) WithTokenVerification(token string) *LarkMiddleware {
opt.enableTokenVerification = true
opt.verificationToken = token
return opt
}
// WithEncryption .
func (opt *LarkMiddleware) WithEncryption(key string) *LarkMiddleware {
opt.enableEncryption = true
opt.encryptKey = lark.EncryptKey(key)
return opt
}
// BindURLPrefix .
func (opt *LarkMiddleware) BindURLPrefix(prefix string) *LarkMiddleware {
opt.enableURLBinding = true
opt.urlPrefix = prefix
return opt
}
// SetMessageKey .
func (opt *LarkMiddleware) SetMessageKey(key string) *LarkMiddleware {
opt.messageKey = key
return opt
}
// SetCardKey .
func (opt *LarkMiddleware) SetCardKey(key string) *LarkMiddleware {
opt.cardKey = key
return opt
}