Add MustEncodeToString for convenience.

This commit is contained in:
Sander Schobers 2021-10-09 19:41:22 +02:00
parent ffc7c1e89b
commit 942bf31ab6

View File

@ -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{}