1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-09 23:22:28 +08:00

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
2022-01-22 14:25:31 +01:00
committed by GitHub
parent 3f8effb7a3
commit 2878d389c8
4 changed files with 90 additions and 0 deletions

View File

@@ -588,3 +588,29 @@ func IsIpV6(ipstr string) bool //check if the string is a ipv6 address
func IsStrongPassword(password string, length int) bool //check if the string is strong password (alpha(lower+upper) + number + special chars(!@#$%^&*()?><))
func IsWeakPassword(password string) bool //check if the string is weak passwordonly letter or only number or letter + number
```
### 14. error helpers
- Contain functions to handle errors
- Usage: import "github.com/duke-git/lancet/xerror"
```go
package main
import (
"fmt"
"io/ioutil"
"log"
"github.com/duke-git/lancet/errors"
)
func main() {
x := Unwrap(strconv.Atoi("42")) // Unwrap if err is nil then it returns a valid value otherwise it panics
}
```
- Function list:
```go
Unwrap[T any](val T, err error)
```