Small code cleanup

This commit is contained in:
2024-12-30 20:53:53 +01:00
parent 4d73c122e3
commit b5a1bfc247
3 changed files with 6 additions and 19 deletions

View File

@ -6,9 +6,7 @@ import (
db2 "code.dlmw.ch/dlmw/qv/internal/db" db2 "code.dlmw.ch/dlmw/qv/internal/db"
"code.dlmw.ch/dlmw/qv/internal/models" "code.dlmw.ch/dlmw/qv/internal/models"
"database/sql" "database/sql"
"github.com/go-playground/form/v4"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
stdlib "github.com/multiprocessio/go-sqlite3-stdlib"
"log/slog" "log/slog"
"net/http" "net/http"
"os" "os"
@ -16,15 +14,13 @@ import (
) )
type application struct { type application struct {
logger *slog.Logger logger *slog.Logger
elections models.ElectionModelInterface elections models.ElectionModelInterface
formDecoder *form.Decoder
} }
var addr = ":8080" var addr = ":8080"
func main() { func main() {
stdlib.Register("sqlite_math_functions")
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil)) logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
db, err := openDb() db, err := openDb()
@ -39,12 +35,9 @@ func main() {
os.Exit(1) os.Exit(1)
} }
formDecoder := form.NewDecoder()
app := &application{ app := &application{
logger: logger, logger: logger,
elections: &models.ElectionModel{DB: db}, elections: &models.ElectionModel{DB: db},
formDecoder: formDecoder,
} }
logger.Info("Starting server", "addr", addr) logger.Info("Starting server", "addr", addr)

View File

@ -2,7 +2,6 @@ package main
import ( import (
"code.dlmw.ch/dlmw/qv/internal/models" "code.dlmw.ch/dlmw/qv/internal/models"
"github.com/go-playground/form/v4"
"io" "io"
"log/slog" "log/slog"
"net/http" "net/http"
@ -11,12 +10,9 @@ import (
) )
func newTestApplication(t *testing.T) *application { func newTestApplication(t *testing.T) *application {
formDecoder := form.NewDecoder()
return &application{ return &application{
logger: slog.New(slog.NewTextHandler(io.Discard, nil)), logger: slog.New(slog.NewTextHandler(io.Discard, nil)),
elections: &models.ElectionModel{}, elections: &models.ElectionModel{},
formDecoder: formDecoder,
} }
} }

2
go.mod
View File

@ -3,11 +3,9 @@ module code.dlmw.ch/dlmw/qv
go 1.23.4 go 1.23.4
require ( require (
github.com/go-playground/form/v4 v4.2.1
github.com/golang-migrate/migrate/v4 v4.18.1 github.com/golang-migrate/migrate/v4 v4.18.1
github.com/justinas/alice v1.2.0 github.com/justinas/alice v1.2.0
github.com/mattn/go-sqlite3 v1.14.24 github.com/mattn/go-sqlite3 v1.14.24
github.com/multiprocessio/go-sqlite3-stdlib v0.0.0-20220822170115-9f6825a1cd25
) )
require ( require (