🧑‍💻 Created Must utility

This commit is contained in:
Maxim Lebedev 2024-05-15 16:45:11 +05:00
parent efe077f181
commit c35fe67be9
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
2 changed files with 9 additions and 10 deletions

View File

@ -24,16 +24,6 @@ func ParseURL(src string) (*URL, error) {
return &URL{URL: u}, nil
}
// MustParseURL parse string as URL or panic.
func MustParseURL(src string) *URL {
uri, err := ParseURL(src)
if err != nil {
panic("MustParseURL: " + err.Error())
}
return uri
}
// TestURL returns URL of provided input for tests.
func TestURL(tb testing.TB, src string) *URL {
tb.Helper()

9
internal/util/must.go Normal file
View File

@ -0,0 +1,9 @@
package util
func Must[T any](v T, err error) T {
if err != nil {
panic(err.Error())
}
return v
}