error: Add unwrap (#24)

Add a unwrap func helper

* Unwrap if err is nil then it returns a valid value otherwise it panics
This commit is contained in:
donutloop authored and GitHub committed 2022-01-22 21:25:31 +08:00
1 parent 3f8effb7a3
commit 2878d389c8
4 files changed
+90

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
// Copyright 2021 dudaodong@gmail.com. All rights reserved.
// Use of this source code is governed by MIT license
// Package xerror implements helpers for errors
package xerror
// Unwrap if err is nil then it returns a valid value
// If err is not nil, Unwrap panics with err.
func Unwrap[T any](val T, err error) T {
if err != nil {
panic(err)
}
return val
}