-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
task.multiply.go
46 lines (38 loc) · 957 Bytes
/
task.multiply.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
package pipeline
import (
"context"
"github.com/pkg/errors"
"go.uber.org/multierr"
)
//
// Return types:
// *decimal.Decimal
//
type MultiplyTask struct {
BaseTask `mapstructure:",squash"`
Input string `json:"input"`
Times string `json:"times"`
}
var _ Task = (*MultiplyTask)(nil)
func (t *MultiplyTask) Type() TaskType {
return TaskTypeMultiply
}
func (t *MultiplyTask) Run(_ context.Context, vars Vars, inputs []Result) (result Result) {
_, err := CheckInputs(inputs, 0, 1, 0)
if err != nil {
return Result{Error: errors.Wrap(err, "task inputs")}
}
var (
a DecimalParam
b DecimalParam
)
err = multierr.Combine(
errors.Wrap(ResolveParam(&a, From(VarExpr(t.Input, vars), Input(inputs, 0))), "input"),
errors.Wrap(ResolveParam(&b, From(VarExpr(t.Times, vars), NonemptyString(t.Times))), "times"),
)
if err != nil {
return Result{Error: err}
}
value := a.Decimal().Mul(b.Decimal())
return Result{Value: value}
}