2022-08-05 19:20:50 +00:00
|
|
|
// Copyright (c) 2022 Tailscale Inc & AUTHORS All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|