resource managment

This commit is contained in:
Dan Ballard 2015-05-17 20:18:28 -07:00
parent 0a1464fd4c
commit 2a13a49474
4 changed files with 6 additions and 2 deletions

View File

@ -27,6 +27,7 @@ func LoadCategories(db *sql.DB) {
fmt.Println("DB Error loading Categories:", err)
return
}
defer rows.Close()
for rows.Next() {
category := &Category{Children: []*Category{}}

View File

@ -63,13 +63,12 @@ func dbConnect() {
if err != nil {
fmt.Println("DB ERROR: ", err)
}
db.SetMaxIdleConns(MAX_DB_CONNS)
err = db.Ping()
if err != nil {
fmt.Println("DB Error on Ping(): ", err)
os.Exit(-1)
}
db.SetMaxIdleConns(MAX_DB_CONNS)
}
func initTemplates() {

View File

@ -66,6 +66,7 @@ func Unexported(db *sql.DB) (map[int]*NewsContainer, int, error) {
fmt.Println("DB errpr reading unexported news: ", err)
return nil, 0, err
}
defer rows.Close()
newsTree := map[int]*NewsContainer{}
newsFlat := map[int]*NewsContainer{}
count := 0

View File

@ -17,6 +17,7 @@ func UsernameExists(db *sql.DB, username string) (bool, error) {
fmt.Println("User DB Error: ", err)
return false, err
}
defer rows.Close()
var count int
rows.Next()
rows.Scan(&count)
@ -30,6 +31,7 @@ func NewUserFromAuth(db *sql.DB, username, password string) *User {
fmt.Println("Username or auth fail: ", err)
return nil
}
defer rows.Close()
user := User{db: db}
if rows.Next() {
err := rows.Scan(&user.Username)
@ -49,6 +51,7 @@ func NewUserFromUsername(db *sql.DB, username string) *User {
fmt.Println("User DB Error: ", err)
return nil
}
defer rows.Close()
user := User{db: db}
if rows.Next() {
err = rows.Scan(&user.Username)