Skip to content

Commit 4f85a3b

Browse files
committed
Resulve issue #224 GetRef() in support package should remove 'vendor' path
allows trigger developer to pass request parameters to handler w/o going through output mapper Resulve issue #224 GetRef() in support package should remove 'vendor' path resubmit pull request to resolve issue #224 Fix #244 Trigger handler should provide option to pass request data to flow without explicit output mapping update per comments on issue #246
1 parent 82972d8 commit 4f85a3b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

trigger/context.go

+19
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,22 @@ func HandlerFromContext(ctx context.Context) (*HandlerInfo, bool) {
2525
u, ok := ctx.Value(handlerKey).(*HandlerInfo)
2626
return u, ok
2727
}
28+
29+
// This allows trigger developer to pass request parameters to handler w/o going through output mapper, e.g.,
30+
// ctx := trigger.NewContextWithValues(context.Background(), values)
31+
// results, err := handler.Handle(ctx, triggerData.ToMap())
32+
33+
type valueKey string
34+
35+
const contextValueKey valueKey = "values"
36+
37+
// NewContextWithValues returns a new Context that carries specified request parameter values
38+
func NewContextWithValues(ctx context.Context, values map[string]interface{}) context.Context {
39+
return context.WithValue(ctx, contextValueKey, values)
40+
}
41+
42+
// ValuesFromContext extracts request parameters from a context
43+
func ValuesFromContext(ctx context.Context) (map[string]interface{}, bool) {
44+
values, ok := ctx.Value(contextValueKey).(map[string]interface{})
45+
return values, ok
46+
}

trigger/handler.go

+7
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ func (h *handlerImpl) Handle(ctx context.Context, triggerData interface{}) (resu
192192
inputMap = triggerValues
193193
}
194194

195+
// extract request parameters from trigger context, and make them available in actions
196+
if reqParams, ok := ValuesFromContext(ctx); ok {
197+
for k, v := range reqParams {
198+
inputMap[k] = v
199+
}
200+
}
201+
195202
if ioMd := act.act.IOMetadata(); ioMd != nil {
196203
for name, tv := range ioMd.Input {
197204
if val, ok := inputMap[name]; ok {

0 commit comments

Comments
 (0)