-
-
Save kennwhite/62a273335358598c61bae943ce155bb7 to your computer and use it in GitHub Desktop.
Wrapping multiple similar calls so that error handling code is reduced.
This file contains hidden or 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
type WriteDB struct { | |
Conn *sql.DB | |
Err error | |
} | |
func (db *WriteDB) Do( | |
update, | |
title, | |
updated_at, | |
updated_by, | |
titleString, | |
) { | |
if db.Err != nil { | |
return | |
} | |
_, db.Err = db.Conn.Exec(update, title, updated_at, updated_by, titleString) | |
} | |
func main() { | |
var db WriteDB | |
db.Conn, db.Err = readDB.Begin() | |
db.Do(stmtUpdateSettings, title, updated_at, updated_by, "title") | |
db.Do(stmtUpdateSettings, logo, updated_at, updated_by, "logo") | |
if db.Err != nil { | |
db.Conn.Rollback() | |
} | |
return db.Conn.Commit() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment