Skip to content

Commit 7518e29

Browse files
committed
Add a basic must package
We keep doing this all over the codebase. Let's just put it here once.
1 parent bf4d48e commit 7518e29

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

must/must.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Package must helps you do things that must not fail.
2+
//
3+
// Example:
4+
//
5+
// var clusterURL = must.Get(url.Parse(...))
6+
// var conn = must.Get(net.Dial("tcp", ...))
7+
// must.Do(telemetry.Shutdown())
8+
package must
9+
10+
// Do panics if err is non-nil.
11+
func Do(err error) {
12+
if err != nil {
13+
panic(err)
14+
}
15+
}
16+
17+
// Get returns v, and panics if err is non-nil.
18+
func Get[T any](v T, err error) T {
19+
if err != nil {
20+
panic(err)
21+
}
22+
return v
23+
}

0 commit comments

Comments
 (0)