-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: must.Do #54297
Comments
I'd support this: we already have other similar APIs like https://pkg.go.dev/text/template#Must and https://pkg.go.dev/regexp#MustCompile, and there's really nothing special about them. Some standard support for |
I realise that some of what I wrote above overlaps with the |
I literally wrote a commit last night and thought, I should propose |
We're using this for our codebase: https://pkg.go.dev/tailscale.com/util/must#Get // Get returns v as is. It panics if err is non-nil.
func Get[T any](v T, err error) T {
if err != nil {
panic(err)
}
return v
} We've found it surprisingly useful ( |
I'm not sure if this should be in the standard library or not. We've all written quickie scripts with |
One question is intent. The tailscale In sufficiently large Go "scripts", you may want some degree of error handling, where the do-or-die approach of |
Some more prior art from the codebase I work on: https://pkg.go.dev/github.com/ridge/must/v2 - |
FYI https://pkg.go.dev/github.com/ridge/must/v2 is deprecated and the fork https://github.com/dottedmag/must is recommended |
I always find it tedious to use
httputil.ReverseProxy
because you usually need a*url.URL
and you can't make one easily without a few lines of boilerplate.Proposal: add
url.MustParse
like regexp.MustCompile, template.Must, etc.(Alternatively: a generic
must.Do
somewhere in std)cc @neild
The text was updated successfully, but these errors were encountered: