-
Notifications
You must be signed in to change notification settings - Fork 14
/
context.go
65 lines (47 loc) · 1.45 KB
/
context.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
package plugin
import (
"context"
"github.com/hashicorp/go-hclog"
"github.com/turbot/steampipe-plugin-sdk/v5/error_helpers"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/context_key"
)
/*
Logger retrieves the [hclog.Logger] from the context.
Log at trace level:
plugin.Logger(ctx).Trace("Code execution starts here")
Log at error level with single data:
plugin.Logger(ctx).Error("hackernews_item.itemList", "query_error", err)
Log at info level with single data:
plugin.Logger(ctx).Info("listGreeting", "number", i)
Log at warn level with multiple data:
plugin.Logger(ctx).Warn("getDomain", "invalid_name", err, "query_response", resp)
*/
func Logger(ctx context.Context) hclog.Logger {
return ctx.Value(context_key.Logger).(hclog.Logger)
}
/*
Deprecated: Please use [plugin.Table.GetMatrixItemFunc] instead.
*/
func GetMatrixItem(ctx context.Context) map[string]interface{} {
value := ctx.Value(context_key.MatrixItem)
if value == nil {
return nil
}
return value.(map[string]interface{})
}
/*
IsCancelled returns whether the context has been cancelled.
To use:
for _, i := range items {
d.StreamListItem(ctx, i)
if plugin.IsCancelled(ctx) {
return nil, nil
}
}
Plugin examples:
- [heroku]
[heroku]: https://github.com/turbot/steampipe-plugin-heroku/blob/a811484d8e29d7478dd9d08adddf0f660563a8ea/heroku/table_heroku_key.go#L58
*/
func IsCancelled(ctx context.Context) bool {
return error_helpers.IsContextCancelledError(ctx.Err())
}