blob: ab0cb4d7e7cc949738cbb17682443d9fc0486292 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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"
uvok_sqlite "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{ServerUrl: "nats://nats-server:4222"}
databasePath := path.Join(workDir, "registrations.sqlite")
repository := uvok_sqlite.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)
}
}
|