mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed Replaced one `WithFxOptionsForService` with fault injection. ## Why We want to eliminate `WithFxOptionsForService` as it is blocking us from migrating away from the `onebox.go` approach (which duplicates the fx setup) since we don't want to expose an equivalent method in `temporal/fx.go`.
36 lines
1.2 KiB
Plaintext
36 lines
1.2 KiB
Plaintext
{{ $decorator := (or .Vars.DecoratorName (printf "faultInjection%s" .Interface.Name)) }}
|
|
|
|
type (
|
|
// {{$decorator}} implements {{.Interface.Name}} interface with fault injection.
|
|
{{$decorator}} struct {
|
|
{{.Interface.Type}}
|
|
generator faultGenerator
|
|
}
|
|
)
|
|
|
|
// new{{upFirst $decorator}} returns {{$decorator}}.
|
|
func new{{upFirst $decorator}} (
|
|
baseStore {{.Interface.Type}},
|
|
generator faultGenerator,
|
|
) *{{$decorator}} {
|
|
return &{{$decorator}} {
|
|
{{.Interface.Name}}: baseStore,
|
|
generator: generator,
|
|
}
|
|
}
|
|
|
|
{{range $method := .Interface.Methods}}
|
|
{{if (and $method.AcceptsContext (gt (len $method.Params) 1)) }}
|
|
{{ $methodIdent := (printf "%s.%s" $.Interface.Name $method.Name) }}
|
|
// {{$method.Name}} wraps {{ (printf "%s.%s" $.Interface.Name $method.Name) }}.
|
|
func (d {{$decorator}}) {{$method.Declaration}} {
|
|
{{- $request := (index $method.Params 1) }}
|
|
err = d.generator.generate("{{ $method.Name }}", {{ $request.Name }}).inject(func() error {
|
|
{{$method.ResultsNames}} = d.{{$.Interface.Name}}.{{$method.Call}}
|
|
return err
|
|
})
|
|
return
|
|
}
|
|
{{end}}
|
|
{{end}}
|