From 5cd70b42bdc8771480f8d18d9d873e1f5c903c56 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sun, 5 Feb 2023 21:10:52 +0400 Subject: [PATCH] Added Guestbook DB to handlers. --- internal/http/handlers.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/internal/http/handlers.go b/internal/http/handlers.go index 291a960..7521503 100644 --- a/internal/http/handlers.go +++ b/internal/http/handlers.go @@ -9,23 +9,34 @@ import ( "git.arav.top/Arav/dwelling-home/pkg/servicestat" "git.arav.top/Arav/dwelling-home/pkg/util" "git.arav.top/Arav/dwelling-home/web" + gbsqlite "git.arav.top/Arav/justguestbook/database/sqlite" ) type Handlers struct { + guestbookDB *gbsqlite.SQLiteDatabase captchaExpire time.Duration databasesPath string guestbookOwner string guestbookPageSize int64 } -func NewHandlers(captchaExpire time.Duration, dbPath, gbOwner string, gbPageSize int) *Handlers { +func NewHandlers(captchaExpire time.Duration, dbPath, gbOwner string, gbPageSize int64) *Handlers { + gbdb, err := gbsqlite.New(dbPath + "/guestbook.sqlite") + if err != nil { + panic(err) + } + return &Handlers{ + guestbookDB: gbdb, captchaExpire: captchaExpire, - databasesPath: dbPath, guestbookOwner: gbOwner, guestbookPageSize: gbPageSize} } +func (h *Handlers) CloseDB() { + h.guestbookDB.Close() +} + func (h *Handlers) AssetsFS() http.FileSystem { return web.Assets() }