resource managment
This commit is contained in:
parent
0a1464fd4c
commit
2a13a49474
|
@ -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{}}
|
||||
|
|
3
main.go
3
main.go
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue