Created
April 26, 2015 02:05
-
-
Save 4ydx/70b732c15d83c294c7dd 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() | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is pseudo-code.