package model import ( "database/sql" ) type Object interface { Create(tx *sql.Tx) error Read(tx *sql.Tx) error Update(tx *sql.Tx) error Delete(tx *sql.Tx) error } func SafeCrud(crud func(tx *sql.Tx) error) error { tx, err := NewTx() if err != nil { return err } err = crud(tx) if err != nil { Rollback(tx) return err } return tx.Commit() }