🧑💻 Created Must utility
This commit is contained in:
parent
efe077f181
commit
c35fe67be9
|
@ -24,16 +24,6 @@ func ParseURL(src string) (*URL, error) {
|
||||||
return &URL{URL: u}, nil
|
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.
|
// TestURL returns URL of provided input for tests.
|
||||||
func TestURL(tb testing.TB, src string) *URL {
|
func TestURL(tb testing.TB, src string) *URL {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
|
|
9
internal/util/must.go
Normal file
9
internal/util/must.go
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
package util
|
||||||
|
|
||||||
|
func Must[T any](v T, err error) T {
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return v
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user