diff options
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/main.go | 42 | 
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 := ®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) +	} +}  | 
