github.com/blend/go-sdk@v1.20220411.3/examples/db/prevent-deadlock/finalize.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package main 9 10 import ( 11 "database/sql" 12 "log" 13 14 "github.com/blend/go-sdk/db" 15 ) 16 17 func ignoreTxDone(err error) error { 18 if err == sql.ErrTxDone { 19 return nil 20 } 21 return err 22 } 23 24 func ignoreConnDone(err error) error { 25 if err == sql.ErrConnDone { 26 return nil 27 } 28 return err 29 } 30 31 func txFinalize(tx *sql.Tx, err error) error { 32 if tx == nil { 33 return err 34 } 35 36 rollbackErr := ignoreTxDone(tx.Rollback()) 37 return nest(err, rollbackErr) 38 } 39 40 func cleanUp(pool *db.Connection) { 41 err := ignoreConnDone(pool.Close()) 42 if err != nil { 43 log.Fatal(err) 44 } 45 }