From e6d7e091b7b6dde1c736e7baf01fad5fd5c1ce27 Mon Sep 17 00:00:00 2001 From: uvok cheetah Date: Fri, 8 Dec 2023 17:05:40 +0000 Subject: Initial Commit --- cmd/main.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 cmd/main.go (limited to 'cmd') 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 := ®istration.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) + } +} -- cgit v1.2.3