-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
58 lines (48 loc) · 991 Bytes
/
options.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
package tim
import (
tenSig "github.com/tencentyun/tls-sig-api-golang"
)
type SigVersion int
const (
VerNew SigVersion = 0
VerOld SigVersion = 1
)
type ServerOption interface {
SetOption(*IMServer) error
}
type SignOption struct {
sigVersion SigVersion
privateKey string
}
func NewSignOption() *SignOption {
return &SignOption{}
}
func (o *SignOption) SetSigVersion(ver SigVersion) *SignOption {
o.sigVersion = ver
return o
}
func (o *SignOption) SetPrivateKey(privateKey string) *SignOption {
o.privateKey = privateKey
return o
}
func (o *SignOption) SetOption(s *IMServer) error {
switch o.sigVersion {
case VerOld:
if o.privateKey == "" {
return ErrInvalidPriKey
}
sig, err := tenSig.GenerateUsersigWithExpire(o.privateKey, s.AppId, s.Identifier, int64(s.Expire))
if err != nil {
return err
}
s.Sig = sig
case VerNew:
var err error
if s.Sig, err = s.userSig(); err != nil {
return err
}
default:
return ErrInvalidVer
}
return nil
}