package overpower import ( "errors" "mule/mybad" "mule/mylog" ) var ( Check = mybad.BuildCheck("package", "overpower") ErrIgnorable = errors.New("something bad happened but we carried on") ErrBadArgs = errors.New("config data for something was bad") WarnLogger = mylog.StockErrorLogger() Ping = WarnLogger.Ping )
package users import ( "mule/mybad" ) var Check = mybad.BuildCheck("package", "users")
package db import ( "database/sql" "fmt" _ "github.com/lib/pq" "mule/mybad" ) var ( Check = mybad.BuildCheck("package", "mydb/db") ErrNoRows = sql.ErrNoRows ) // SQLer allows functions to use either db or tx type DBer interface { Exec(string, ...interface{}) (sql.Result, error) QueryRow(string, ...interface{}) *sql.Row Query(string, ...interface{}) (*sql.Rows, error) Prepare(string) (*sql.Stmt, error) } // Maybe this shouldn't be here to keep this package SQL-flavor agnostic. // Who knows? Useful for me, for now. func LoadDB(user, pass, dbName string) (db *sql.DB, err error) { db, err = sql.Open("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=disable", user, pass, dbName)) if my, bad := Check(err, "loaddb failure", "username", user, "dbname", dbName); bad { return nil, my } err = db.Ping() if my, bad := Check(err, "loaddb ping failure", "username", user, "dbname", dbName); bad {
package group import ( "mule/mybad" sq "mule/mydb/sql" ) var ( Check = mybad.BuildCheck("package", "mydb/group") ) // SQLStruct is just something for templating generics type SQLStruct struct { INSERT bool DELETE bool UPDATE bool } func WherePK(pkCols []string) sq.Condition { wheres := make([]sq.P, len(pkCols)) for i, col := range pkCols { wheres[i] = sq.P{col, nil} } return sq.AllEQ( wheres..., ) } type GroupMaker interface { SQLGroup() SQLGrouper }
package models import ( "mule/mybad" "mule/mydb/db" sq "mule/mydb/sql" ) var ( Check = mybad.BuildCheck("package", "models") ) type Manager struct { D db.DBer BattleRecordSession *BattleRecordSession FactionSession *FactionSession GameSession *GameSession LaunchRecordSession *LaunchRecordSession MapViewSession *MapViewSession LaunchOrderSession *LaunchOrderSession PlanetSession *PlanetSession PlanetViewSession *PlanetViewSession PowerOrderSession *PowerOrderSession ShipSession *ShipSession ShipViewSession *ShipViewSession TruceSession *TruceSession } func NewManager(d db.DBer) *Manager { return &Manager{D: d} }