-
Notifications
You must be signed in to change notification settings - Fork 8
/
generic.go
57 lines (46 loc) · 1.41 KB
/
generic.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
package functions
import (
"context"
"github.com/Velocidex/ordereddict"
"www.velocidex.com/golang/vfilter/types"
)
// Generic synchronous plugins just return all their rows at once.
type GenericFunctionInterface func(ctx context.Context, scope types.Scope, args *ordereddict.Dict) types.Any
// A generic plugin based on a function returning a slice of
// rows. Many simpler plugins do not need an asynchronous interface
// because they may obtain all their rows in one operation. This
// helper plugin allows callers to use these within VFilter
// easily. Example:
// scope.AppendPlugins(GenericListPlugin{
// PluginName: "my_plugin",
// Function: func(args types.Row) []types.Row {
// ....
// }
// })
type GenericFunction struct {
FunctionName string
Doc string
Function GenericFunctionInterface
Metadata *ordereddict.Dict
ArgType types.Any
}
func (self GenericFunction) Copy() types.FunctionInterface {
return self
}
func (self GenericFunction) Call(
ctx context.Context,
scope types.Scope,
args *ordereddict.Dict) types.Any {
return self.Function(ctx, scope, args)
}
func (self GenericFunction) Info(scope types.Scope, type_map *types.TypeMap) *types.FunctionInfo {
result := &types.FunctionInfo{
Name: self.FunctionName,
Doc: self.Doc,
Metadata: self.Metadata,
}
if self.ArgType != nil {
result.ArgType = type_map.AddType(scope, self.ArgType)
}
return result
}