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)
|
fmt.Println("DB Error loading Categories:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
category := &Category{Children: []*Category{}}
|
category := &Category{Children: []*Category{}}
|
||||||
|
|
3
main.go
3
main.go
|
@ -63,13 +63,12 @@ func dbConnect() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("DB ERROR: ", err)
|
fmt.Println("DB ERROR: ", err)
|
||||||
}
|
}
|
||||||
|
db.SetMaxIdleConns(MAX_DB_CONNS)
|
||||||
err = db.Ping()
|
err = db.Ping()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("DB Error on Ping(): ", err)
|
fmt.Println("DB Error on Ping(): ", err)
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
db.SetMaxIdleConns(MAX_DB_CONNS)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func initTemplates() {
|
func initTemplates() {
|
||||||
|
|
|
@ -66,6 +66,7 @@ func Unexported(db *sql.DB) (map[int]*NewsContainer, int, error) {
|
||||||
fmt.Println("DB errpr reading unexported news: ", err)
|
fmt.Println("DB errpr reading unexported news: ", err)
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
defer rows.Close()
|
||||||
newsTree := map[int]*NewsContainer{}
|
newsTree := map[int]*NewsContainer{}
|
||||||
newsFlat := map[int]*NewsContainer{}
|
newsFlat := map[int]*NewsContainer{}
|
||||||
count := 0
|
count := 0
|
||||||
|
|
|
@ -17,6 +17,7 @@ func UsernameExists(db *sql.DB, username string) (bool, error) {
|
||||||
fmt.Println("User DB Error: ", err)
|
fmt.Println("User DB Error: ", err)
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
defer rows.Close()
|
||||||
var count int
|
var count int
|
||||||
rows.Next()
|
rows.Next()
|
||||||
rows.Scan(&count)
|
rows.Scan(&count)
|
||||||
|
@ -30,6 +31,7 @@ func NewUserFromAuth(db *sql.DB, username, password string) *User {
|
||||||
fmt.Println("Username or auth fail: ", err)
|
fmt.Println("Username or auth fail: ", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
defer rows.Close()
|
||||||
user := User{db: db}
|
user := User{db: db}
|
||||||
if rows.Next() {
|
if rows.Next() {
|
||||||
err := rows.Scan(&user.Username)
|
err := rows.Scan(&user.Username)
|
||||||
|
@ -49,6 +51,7 @@ func NewUserFromUsername(db *sql.DB, username string) *User {
|
||||||
fmt.Println("User DB Error: ", err)
|
fmt.Println("User DB Error: ", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
defer rows.Close()
|
||||||
user := User{db: db}
|
user := User{db: db}
|
||||||
if rows.Next() {
|
if rows.Next() {
|
||||||
err = rows.Scan(&user.Username)
|
err = rows.Scan(&user.Username)
|
||||||
|
|
Loading…
Reference in New Issue