From 0e6baecebbf8a24a6590d3fc8232165008d6e5d8 Mon Sep 17 00:00:00 2001 From: savaki Date: Thu, 8 Dec 2016 17:38:33 -0800 Subject: [PATCH] - added support for Must --- parse.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/parse.go b/parse.go index b1bb6fa..3c21e06 100644 --- a/parse.go +++ b/parse.go @@ -15,6 +15,7 @@ package jq import ( + "fmt" "regexp" "strconv" "strings" @@ -24,6 +25,15 @@ var ( reArray = regexp.MustCompile(`^\s*\[\s*(\d+)(\s*:\s*(\d+))?\s*]\s*$`) ) +// Must is a convenience method similar to template.Must +func Must(op Op, err error) Op { + if err != nil { + panic(fmt.Errorf("unable to parse selector; %v", err.Error())) + } + + return op +} + // Parse takes a string representation of a selector and returns the corresponding Op definition func Parse(selector string) (Op, error) { segments := strings.Split(selector, ".")