From b9d0348735670ab80b12c2305fa6d3ae2fddfc4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Fri, 19 Jan 2024 17:30:20 +0100 Subject: [PATCH] v0.0.379 --- goextVersion.go | 4 ++-- langext/must.go | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 langext/must.go diff --git a/goextVersion.go b/goextVersion.go index b700a35..8d8ffdf 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -1,5 +1,5 @@ package goext -const GoextVersion = "0.0.378" +const GoextVersion = "0.0.379" -const GoextVersionTimestamp = "2024-01-16T15:04:10+0100" +const GoextVersionTimestamp = "2024-01-19T17:30:20+0100" diff --git a/langext/must.go b/langext/must.go new file mode 100644 index 0000000..3c6925b --- /dev/null +++ b/langext/must.go @@ -0,0 +1,21 @@ +package langext + +// Must returns a value and panics on error +// +// Usage: Must(methodWithError(...)) +func Must[T any](v T, err error) T { + if err != nil { + panic(err) + } + return v +} + +// MustBool returns a value and panics on missing +// +// Usage: MustBool(methodWithOkayReturn(...)) +func MustBool[T any](v T, ok bool) T { + if !ok { + panic("not ok") + } + return v +}