Skip to content

Instantly share code, notes, and snippets.

@AnuchitO
Last active September 24, 2019 02:29
Show Gist options
  • Save AnuchitO/b79478dace5497b9de87c67e9ec3219a to your computer and use it in GitHub Desktop.
Save AnuchitO/b79478dace5497b9de87c67e9ec3219a to your computer and use it in GitHub Desktop.
func insertInfo() error {
// do work here.
return sql.ErrTxDone
}
func main() {
// จากแบบเดิม
err := insertInfo()
if err == sql.ErrTxDone {
fmt.Println("old way: compare error with sql.ErrTxDone")
}
// เป็นแบบนี้แทน
err = insertInfo()
if errors.Is(err, sql.ErrTxDone) {
fmt.Println("new way: compare error with sql.ErrTxDone")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment