summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authoruvok cheetah2023-12-08 17:05:40 +0000
committeruvok cheetah2023-12-08 17:05:40 +0000
commite6d7e091b7b6dde1c736e7baf01fad5fd5c1ce27 (patch)
tree38a11d4df6a3661ba9eec8d0e7c7df0d9116a19d /cmd
Initial Commit
Diffstat (limited to 'cmd')
-rw-r--r--cmd/main.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/cmd/main.go b/cmd/main.go
new file mode 100644
index 0000000..4ff1658
--- /dev/null
+++ b/cmd/main.go
@@ -0,0 +1,42 @@
+package main
+
+import (
+ "context"
+ "log"
+ "net/http"
+ "os"
+ "path"
+
+ "uvok.de/go/training_fellow/registration"
+ myhttp "uvok.de/go/training_fellow/registration/http"
+ "uvok.de/go/training_fellow/registration/http/rest"
+ "uvok.de/go/training_fellow/registration/nats"
+ persistence "uvok.de/go/training_fellow/registration/persistence/sqlite"
+)
+
+func main() {
+ log.Print("Starting application")
+ workDir, err := os.Getwd()
+ context := context.Background()
+ if err != nil {
+ workDir = "."
+ }
+
+ notifier := &nats.NatsNotifier{}
+
+ databasePath := path.Join(workDir, "registrations.sqlite")
+ repository := persistence.NewRepository(databasePath, context)
+ service := &registration.RegistrationService{Notifier: notifier, Repository: repository}
+ handler := &rest.RegistrationHandler{Service: service}
+
+ newRegistrationHandler := rest.HandleRegistration(handler)
+
+ contentHandler := myhttp.IsFormContentCheck(newRegistrationHandler)
+ http.Handle("/register", contentHandler)
+ http.Handle("/registrations", rest.HandleGetRegistrations(handler))
+ log.Print("Starting server")
+ err = http.ListenAndServe(":8080", nil)
+ if err != nil {
+ log.Fatalf("Error starting HTTP server: %v", err)
+ }
+}