moved webhook initialization down

This commit is contained in:
2026-01-11 15:42:03 -07:00
parent 388902a1a0
commit 23f527b769
2 changed files with 40 additions and 41 deletions
+18 -41
View File
@@ -23,8 +23,6 @@ import (
etsy_platform "ruben/inventory2/internal/domains/platforms/etsy"
"ruben/inventory2/internal/domains/raw_events"
"ruben/inventory2/internal/server"
"ruben/inventory2/internal/server/webhooks"
etsy_webhooks "ruben/inventory2/internal/server/webhooks/etsy"
)
const (
@@ -141,8 +139,24 @@ func runAuthProcesses(ctx context.Context, auth *authentication.Authenticator) <
func runServer(ctx context.Context, logger *slog.Logger, connPool *pgxpool.Pool, auth *authentication.Authenticator) <-chan error {
srv := &http.Server{
Addr: ":8082", // local
Handler: buildHTTPHandler(logger, connPool, auth),
Addr: ":8082", // local
Handler: server.NewServer(
logger.WithGroup("server"),
// TODO: consider moving the templates up to a higher level...
"./internal/server",
raw_events.NewStore(logger.WithGroup("raw-event-store"), connPool),
accounts.NewStore(logger, connPool),
etsy_platform.NewPlatform(
logger,
func(acctID int64) string {
return fmt.Sprintf("/oauth/account/%d/auth_code", acctID)
},
etsyAPIKeystring,
etsyAPISharedSecret,
connPool,
),
auth,
),
}
ctx, cancel := context.WithCancel(ctx)
@@ -192,40 +206,3 @@ func runServer(ctx context.Context, logger *slog.Logger, connPool *pgxpool.Pool,
return errCh
}
func buildHTTPHandler(logger *slog.Logger, connPool *pgxpool.Pool, auth *authentication.Authenticator) http.Handler {
eventsDB := raw_events.NewStore(logger.WithGroup("raw-event-store"), connPool)
etsy := etsy_platform.NewPlatform(
logger,
func(acctID int64) string {
return fmt.Sprintf("/oauth/account/%d/auth_code", acctID)
},
etsyAPIKeystring,
etsyAPISharedSecret,
connPool,
)
accts := accounts.NewStore(logger, connPool)
mux := http.NewServeMux()
mux.Handle("/webhooks/", http.StripPrefix("/webhooks", webhooks.New(
logger.WithGroup("webhooks"),
eventsDB,
etsy,
webhooks.Config{
Etsy: etsy_webhooks.Config{
OAuthRedirectURIWithAcctIDParam: "/oauth/account/{acctID}/auth_code",
},
},
)))
mux.Handle("/", server.NewServer(
logger.WithGroup("server"),
"./internal/server",
eventsDB,
accts,
etsy,
auth,
))
return mux
}