1
0

Create an instance of DB in main instead.

This commit is contained in:
Alexander Andreev 2023-05-09 23:35:08 +04:00
parent 3bb97a424f
commit f8a8d948a4
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -7,11 +7,13 @@ import (
"net/netip"
"os"
"os/signal"
"path"
"strings"
"syscall"
"time"
"git.arav.su/Arav/dwelling-home/internal/http"
"git.arav.su/Arav/justguestbook/database/sqlite"
)
var version string
@ -48,7 +50,13 @@ func main() {
}
}
hand := http.NewHandlers(*captchaExpiry, *databasesPath, *guestbookOwner, *guestbookPageSize)
guestbookDB, err := sqlite.New(path.Join(*databasesPath, "guestbook.sqlite"))
if err != nil {
log.Fatalln(err)
}
defer guestbookDB.Close()
hand := http.NewHandlers(*captchaExpiry, *guestbookOwner, *guestbookPageSize, guestbookDB)
defer hand.CloseDB()
srv := http.NewHttpServer()
@ -73,7 +81,7 @@ func main() {
srv.POST("/api/captcha/:id", captchaApi.Solve)
srv.GET("/api/captcha/:id/image", captchaApi.Image)
guestbookApi := http.NewGuestbookApiHandlers(*databasesPath, *guestbookOwner, *guestbookPageSize)
guestbookApi := http.NewGuestbookApiHandlers(*guestbookOwner, *guestbookPageSize, guestbookDB)
srv.POST("/api/guestbook", guestbookApi.New)
srv.PATCH("/api/guestbook/:id", guestbookApi.Edit)