From 43df6150b413eb3bbc1377c3a98b163c1cf080bd Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Thu, 18 Nov 2021 14:58:29 +0100 Subject: [PATCH] Introduce MustConstraints() --- constraint.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/constraint.go b/constraint.go index d055759..df3fca2 100644 --- a/constraint.go +++ b/constraint.go @@ -66,6 +66,16 @@ func NewConstraint(v string) (Constraints, error) { return Constraints(result), nil } +// MustConstraints is a helper that wraps a call to a function +// returning (Constraints, error) and panics if error is non-nil. +func MustConstraints(c Constraints, err error) Constraints { + if err != nil { + panic(err) + } + + return c +} + // Check tests if a version satisfies all the constraints. func (cs Constraints) Check(v *Version) bool { for _, c := range cs {