Skip to content

Instantly share code, notes, and snippets.

@shumon84
Created November 22, 2018 01:59
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 shumon84/ee409b7c9faca0c8e6bfbd0e0dc9a353 to your computer and use it in GitHub Desktop.
Save shumon84/ee409b7c9faca0c8e6bfbd0e0dc9a353 to your computer and use it in GitHub Desktop.
func main(){
db, _ := sql.Open("mysql", "user:password@tcp(host:port)/dbname")
tx, _ := db.Begin()
defer func() {
// panicが起きたらロールバック
if recover() != nil {
tx.Rollback()
}
}()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment