From 942bf31ab69b82196782aa7f35dbba692310a3e0 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Sat, 9 Oct 2021 19:41:22 +0200 Subject: [PATCH] Add MustEncodeToString for convenience. --- utio/string.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/utio/string.go b/utio/string.go index 6162403..5eb4cc8 100644 --- a/utio/string.go +++ b/utio/string.go @@ -17,6 +17,15 @@ func EncodeToString(e Encoder) (string, error) { return WriteToString(e.Encode) } +// MustEncodeToString returns the encoded string value and panics if an error has occurred +func MustEncodeToString(e Encoder) string { + s, err := WriteToString(e.Encode) + if err != nil { + panic(err) + } + return s +} + // WriteToString returns the string value of the data written to fn. func WriteToString(fn WriteFunc) (string, error) { var b = &bytes.Buffer{}