raw_store_events store started
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"ruben/inventory2/internal/domains/raw_events"
|
||||
"ruben/inventory2/internal/site"
|
||||
"ruben/inventory2/internal/webhooks"
|
||||
)
|
||||
@@ -25,9 +26,16 @@ func runApp(ctx context.Context) error {
|
||||
ctx, shutdown := context.WithCancel(ctx)
|
||||
defer shutdown()
|
||||
|
||||
// connect to the database
|
||||
|
||||
db, err := raw_events.NewStore(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to initialize the raw event store: %w", err)
|
||||
}
|
||||
|
||||
// start http server
|
||||
|
||||
srvErrCh := runServer(ctx)
|
||||
srvErrCh := runServer(ctx, db)
|
||||
|
||||
// wait for interrupt signal or unrecoverable failure, then shutdown
|
||||
|
||||
@@ -63,19 +71,10 @@ func runApp(ctx context.Context) error {
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
|
||||
func buildHTTPHandler() http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
mux.Handle("/webhooks/", http.StripPrefix("/webhooks", webhooks.New()))
|
||||
mux.Handle("/site/", http.StripPrefix("/site", site.NewSiteHandler()))
|
||||
|
||||
return mux
|
||||
}
|
||||
|
||||
func runServer(ctx context.Context) <-chan error {
|
||||
func runServer(ctx context.Context, db *raw_events.Store) <-chan error {
|
||||
srv := &http.Server{
|
||||
Addr: ":9000", // local
|
||||
Handler: buildHTTPHandler(),
|
||||
Handler: buildHTTPHandler(db),
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
@@ -125,3 +124,12 @@ func runServer(ctx context.Context) <-chan error {
|
||||
|
||||
return errCh
|
||||
}
|
||||
|
||||
func buildHTTPHandler(db *raw_events.Store) http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
mux.Handle("/webhooks/", http.StripPrefix("/webhooks", webhooks.New(db)))
|
||||
mux.Handle("/site/", http.StripPrefix("/site", site.NewSiteHandler()))
|
||||
|
||||
return mux
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user