Created
March 29, 2022 20:58
-
-
Save pavelaron/ed8529775c66c7ce27a7d46a88d740fd to your computer and use it in GitHub Desktop.
Go error handling with generics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage e.g.: f := check(os.Create(filePath)) | |
func check[T any] (result T, err error) (output T) { | |
if err == nil { | |
return result | |
} | |
fmt.Println(err) | |
panic(err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment