add errcode func

This commit is contained in:
张开元
2024-12-19 20:26:39 +08:00
parent dcd252f802
commit ed8fdebc81
2 changed files with 19 additions and 0 deletions

View File

@@ -227,3 +227,16 @@ func GetErrorCode(err error) (errCode int) {
}
return
}
func GetErrorByCode(errCode int) (error) {
if errCode < 0 {
return nil
}
for key, value := range errorsMap {
if value == errCode {
return key
}
}
return nil
}

View File

@@ -10,3 +10,9 @@ func TestGetErrorCode(t *testing.T) {
code := GetErrorCode(err)
fmt.Println(code)
}
func TestGetErrorByCode(t *testing.T) {
code := 0
err := GetErrorByCode(code)
fmt.Println("[TestGetErrorByCode]:err:",err)
}