func (v *AdditiveValue) Resolve(context *Context) interface{} { a := v.a.Resolve(context) b := v.b.Resolve(context) if na, ok := r.ToInt(a); ok { if nb, ok := r.ToInt(b); ok { if v.negate { nb = -nb } return na + nb } } else if fa, ok := r.ToFloat(a); ok { if fb, ok := r.ToFloat(b); ok { if v.negate { fb = -fb } return fa + fb } } else if ta, ok := a.(time.Duration); ok { if tb, ok := b.(time.Duration); ok { if v.negate { return ta - tb } return ta + tb } } if v.negate { return loggedOperationNil(a, b, "-", 0) } return loggedOperationNil(a, b, "+", 0) }
func (v *MultiplicativeValue) Resolve(context *Context) interface{} { a := v.a.Resolve(context) b := v.b.Resolve(context) if na, ok := r.ToInt(a); ok { if nb, ok := r.ToInt(b); ok { if v.divide { return na / nb } return na * nb } } else if fa, ok := r.ToFloat(a); ok { if fb, ok := r.ToFloat(b); ok { if v.divide { return fa / fb } return fa * fb } } else if ta, ok := a.(time.Duration); ok { if tb, ok := b.(time.Duration); ok { if v.divide { return ta / tb } return ta * tb } } if v.divide { return loggedOperationNil(a, b, "/", 0) } return loggedOperationNil(a, b, "*", 0) }