summaryrefslogtreecommitdiffstats
path: root/cmd/web/main.go
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-02-09 16:38:46 +0000
committerMatthew Lemon <y@yulqen.org>2024-02-09 16:38:46 +0000
commit7c4a913645ba1e347ab94097de44eb04d7df4e47 (patch)
tree82fe2f9db6c549756f4f1e96ff1e781c0099603c /cmd/web/main.go
parentb8ed10b800d24a94bb6a9339d5764c6dbe7d9f6e (diff)
Adds the Organisations model
We have separation of concerns: the model is initalised and passed into the app struct, therefore our database logic will not be tied to our handlers. Our model, with its methods, is nicely encapsulated. We can initialise it and pass it to our handlers as a dependency. We can in future create an interface to mock the OrganisationModel object to be used in unit testing. We can also switch databases (theoretically) but providing a -dsn command-line flag.
Diffstat (limited to '')
-rw-r--r--cmd/web/main.go7
1 files changed, 5 insertions, 2 deletions
diff --git a/cmd/web/main.go b/cmd/web/main.go
index b767275..cbfda5e 100644
--- a/cmd/web/main.go
+++ b/cmd/web/main.go
@@ -8,10 +8,12 @@ import (
"os"
_ "github.com/go-sql-driver/mysql"
+ "github.com/yulqen/ded-go-core/internal/models"
)
type application struct {
- logger *slog.Logger
+ logger *slog.Logger
+ organisations *models.OrganisationModel
}
func main() {
@@ -31,7 +33,8 @@ func main() {
defer db.Close()
app := &application{
- logger: logger,
+ logger: logger,
+ organisations: &models.OrganisationModel{DB: db},
}
// mux := http.NewServeMux()