2023-01-27 21:37:20 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2022-08-05 19:20:50 +00:00
|
|
|
|
|
|
|
// Package must assists in calling functions that must succeed.
|
|
|
|
//
|
|
|
|
// Example usage:
|
2022-08-06 05:39:17 +00:00
|
|
|
//
|
|
|
|
// var target = must.Get(url.Parse(...))
|
|
|
|
// must.Do(close())
|
2022-08-05 19:20:50 +00:00
|
|
|
package must
|
|
|
|
|
2022-08-06 05:39:17 +00:00
|
|
|
// Do panics if err is non-nil.
|
|
|
|
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 {
|
2022-08-05 19:20:50 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|