generated from dronestock/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.go
44 lines (37 loc) · 1.03 KB
/
token.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
package step
import (
"context"
"github.com/dronestock/drone"
"github.com/dronestock/feishu/internal/config"
"github.com/dronestock/feishu/internal/step/internal/constant"
"github.com/dronestock/feishu/internal/step/internal/feishu/token"
"github.com/goexl/exception"
"github.com/goexl/gox/field"
)
type Token struct {
base *drone.Base
app *config.App
}
func NewToken(base *drone.Base, app *config.App) *Token {
return &Token{
base: base,
app: app,
}
}
func (t *Token) Runnable() bool {
return true
}
func (t *Token) Run(ctx *context.Context) (err error) {
rsp := new(token.Response)
req := new(token.Request)
req.Id = t.app.Id
req.Secret = t.app.Secret
if response, pe := t.base.Http().R().SetContext(*ctx).SetBody(req).SetResult(rsp).Post(constant.TokenUrl); nil != pe {
err = pe
} else if response.IsError() {
err = exception.New().Message("飞书返回错误").Field(field.New("response", string(response.Body()))).Build()
} else {
*ctx = context.WithValue(*ctx, constant.ContextKeyToken, rsp.Token)
}
return
}