-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrapperfuncs.go
50 lines (43 loc) · 1.5 KB
/
wrapperfuncs.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
package function
import (
"context"
)
type StringArgsFunc func(ctx context.Context, args ...string) error
func NewStringArgsFunc(f CallWithStringsWrapper, resultsHandlers ...ResultsHandler) StringArgsFunc {
return func(ctx context.Context, args ...string) error {
results, resultErr := f.CallWithStrings(ctx, args...)
for _, resultsHandler := range resultsHandlers {
err := resultsHandler.HandleResults(ctx, results, resultErr)
if err != nil && err != resultErr {
return err
}
}
return resultErr
}
}
type NamedStringArgsFunc func(ctx context.Context, args map[string]string) error
func NewNamedStringArgsFunc(f CallWithNamedStringsWrapper, resultsHandlers ...ResultsHandler) NamedStringArgsFunc {
return func(ctx context.Context, args map[string]string) error {
results, resultErr := f.CallWithNamedStrings(ctx, args)
for _, resultsHandler := range resultsHandlers {
err := resultsHandler.HandleResults(ctx, results, resultErr)
if err != nil && err != resultErr {
return err
}
}
return resultErr
}
}
type JSONArgsFunc func(ctx context.Context, jsonObject []byte) error
func NewJSONArgsFunc(f Wrapper, resultsHandlers ...ResultsHandler) JSONArgsFunc {
return func(ctx context.Context, jsonObject []byte) error {
results, resultErr := CallFunctionWithJSONArgs(ctx, f, jsonObject)
for _, resultsHandler := range resultsHandlers {
err := resultsHandler.HandleResults(ctx, results, resultErr)
if err != nil && err != resultErr {
return err
}
}
return resultErr
}
}