mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 13:05:46 +00:00
util/must: rename Do->Get, add Do
Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
parent
ec9d13bce5
commit
40ec8617ac
@ -5,11 +5,20 @@
|
|||||||
// Package must assists in calling functions that must succeed.
|
// Package must assists in calling functions that must succeed.
|
||||||
//
|
//
|
||||||
// Example usage:
|
// Example usage:
|
||||||
// var target = must.Do(url.Parse(...))
|
//
|
||||||
|
// var target = must.Get(url.Parse(...))
|
||||||
|
// must.Do(close())
|
||||||
package must
|
package must
|
||||||
|
|
||||||
// Do returns v as is. It panics if err is non-nil.
|
// Do panics if err is non-nil.
|
||||||
func Do[T any](v T, err error) T {
|
func Do(err error) {
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns v as is. It panics if err is non-nil.
|
||||||
|
func Get[T any](v T, err error) T {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user