type Modules property of WrappedPayload

This commit is contained in:
Joel Wetzell
2026-03-18 16:24:49 -05:00
parent 2fbca6209e
commit 1fb59cc947
4 changed files with 21 additions and 36 deletions

View File

@@ -6,30 +6,35 @@ import (
type WrappedPayload struct { type WrappedPayload struct {
Payload any Payload any
Modules any Modules map[string]Module
Sender any Sender any
Source string Source string
End bool End bool
} }
func GetWrappedPayload(ctx context.Context, payload any) WrappedPayload { func GetWrappedPayload(ctx context.Context, payload any) WrappedPayload {
templateData := WrappedPayload{ wrappedPayload := WrappedPayload{
Payload: payload, Payload: payload,
End: false, End: false,
} }
modules := ctx.Value(ModulesContextKey) modules := ctx.Value(ModulesContextKey)
if modules != nil { if modules != nil {
templateData.Modules = modules moduleMap, ok := modules.(map[string]Module)
if ok {
wrappedPayload.Modules = moduleMap
} else {
wrappedPayload.Modules = make(map[string]Module)
}
} }
sender := ctx.Value(SenderContextKey) sender := ctx.Value(SenderContextKey)
if sender != nil { if sender != nil {
templateData.Sender = sender wrappedPayload.Sender = sender
} }
source := ctx.Value(SourceContextKey) source := ctx.Value(SourceContextKey)
if source != nil { if source != nil {
templateData.Source = source.(string) wrappedPayload.Source = source.(string)
} }
return templateData return wrappedPayload
} }

View File

@@ -18,19 +18,12 @@ type DbQuery struct {
} }
func (dq *DbQuery) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) { func (dq *DbQuery) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
ctxModules := ctx.Value(common.ModulesContextKey) if wrappedPayload.Modules == nil {
if ctxModules == nil {
wrappedPayload.End = true wrappedPayload.End = true
return wrappedPayload, errors.New("db.query unable to get modules from context") return wrappedPayload, errors.New("db.query wrapped payload has no modules")
} }
moduleMap, ok := ctxModules.(map[string]common.Module) module, ok := wrappedPayload.Modules[dq.ModuleId]
if !ok {
wrappedPayload.End = true
return wrappedPayload, errors.New("db.query modules from context has wrong type")
}
module, ok := moduleMap[dq.ModuleId]
if !ok { if !ok {
wrappedPayload.End = true wrappedPayload.End = true
return wrappedPayload, fmt.Errorf("db.query unable to find module with id: %s", dq.ModuleId) return wrappedPayload, fmt.Errorf("db.query unable to find module with id: %s", dq.ModuleId)

View File

@@ -18,19 +18,12 @@ type KVGet struct {
} }
func (kvg *KVGet) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) { func (kvg *KVGet) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
ctxModules := ctx.Value(common.ModulesContextKey) if wrappedPayload.Modules == nil {
if ctxModules == nil {
wrappedPayload.End = true wrappedPayload.End = true
return wrappedPayload, errors.New("kv.get unable to get modules from context") return wrappedPayload, errors.New("kv.get wrapped payload has no modules")
} }
moduleMap, ok := ctxModules.(map[string]common.Module) module, ok := wrappedPayload.Modules[kvg.ModuleId]
if !ok {
wrappedPayload.End = true
return wrappedPayload, errors.New("kv.get modules from context has wrong type")
}
module, ok := moduleMap[kvg.ModuleId]
if !ok { if !ok {
wrappedPayload.End = true wrappedPayload.End = true
return wrappedPayload, fmt.Errorf("kv.get unable to find module with id: %s", kvg.ModuleId) return wrappedPayload, fmt.Errorf("kv.get unable to find module with id: %s", kvg.ModuleId)

View File

@@ -20,19 +20,13 @@ type KVSet struct {
} }
func (kvs *KVSet) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) { func (kvs *KVSet) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
ctxModules := ctx.Value(common.ModulesContextKey)
if ctxModules == nil { if wrappedPayload.Modules == nil {
wrappedPayload.End = true wrappedPayload.End = true
return wrappedPayload, errors.New("kv.set unable to get modules from context") return wrappedPayload, errors.New("kv.set wrapped payload has no modules")
} }
moduleMap, ok := ctxModules.(map[string]common.Module) module, ok := wrappedPayload.Modules[kvs.ModuleId]
if !ok {
wrappedPayload.End = true
return wrappedPayload, errors.New("kv.set modules from context has wrong type")
}
module, ok := moduleMap[kvs.ModuleId]
if !ok { if !ok {
wrappedPayload.End = true wrappedPayload.End = true
return wrappedPayload, fmt.Errorf("kv.set unable to find module with id: %s", kvs.ModuleId) return wrappedPayload, fmt.Errorf("kv.set unable to find module with id: %s", kvs.ModuleId)