Skip to content

Instantly share code, notes, and snippets.

@pavelaron
Created March 29, 2022 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavelaron/ed8529775c66c7ce27a7d46a88d740fd to your computer and use it in GitHub Desktop.
Save pavelaron/ed8529775c66c7ce27a7d46a88d740fd to your computer and use it in GitHub Desktop.
Go error handling with generics
// 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