- commit
- 1317d25
- parent
- 2f0f0ee
- author
- Eric Bower
- date
- 2024-03-01 04:30:04 +0000 UTC
refactor: shared router
7 files changed,
+2,
-8
+0,
-1
1@@ -68,7 +68,6 @@ func StartApiServer() {
2 Cfg: cfg,
3 Dbpool: db,
4 Storage: st,
5- Logger: logger,
6 }
7 handler := shared.CreateServe(mainRoutes, []shared.Route{}, httpCtx)
8 router := http.HandlerFunc(handler)
+0,
-1
1@@ -326,7 +326,6 @@ func StartApiServer() {
2 Cfg: cfg,
3 Dbpool: db,
4 Storage: st,
5- Logger: logger,
6 }
7 handler := shared.CreateServe(mainRoutes, subdomainRoutes, httpCtx)
8 router := http.HandlerFunc(handler)
+0,
-1
1@@ -383,7 +383,6 @@ func StartApiServer() {
2 Cfg: cfg,
3 Dbpool: db,
4 Storage: st,
5- Logger: logger,
6 }
7 handler := shared.CreateServe(mainRoutes, subdomainRoutes, httpCtx)
8 router := http.HandlerFunc(handler)
+0,
-1
1@@ -492,7 +492,6 @@ func StartApiServer() {
2 Cfg: cfg,
3 Dbpool: db,
4 Storage: st,
5- Logger: logger,
6 }
7 handler := shared.CreateServe(mainRoutes, createSubdomainRoutes(publicPerm), httpCtx)
8 router := http.HandlerFunc(handler)
+1,
-1
1@@ -94,7 +94,7 @@ func createHttpHandler(httpCtx *shared.HttpCtx) CtxHttpBridge {
2 return func(ctx ssh.Context) http.Handler {
3 subdomain := ctx.User()
4 dbh := httpCtx.Dbpool
5- logger := httpCtx.Logger
6+ logger := httpCtx.Cfg.Logger
7 log := logger.With(
8 "subdomain", subdomain,
9 )
+0,
-1
1@@ -895,7 +895,6 @@ func StartApiServer() {
2 Cfg: cfg,
3 Dbpool: db,
4 Storage: st,
5- Logger: logger,
6 }
7 handler := shared.CreateServe(mainRoutes, subdomainRoutes, httpCtx)
8 router := http.HandlerFunc(handler)
1@@ -45,14 +45,13 @@ func CreatePProfRoutes(routes []Route) []Route {
2
3 type ServeFn func(http.ResponseWriter, *http.Request)
4 type HttpCtx struct {
5- Logger *slog.Logger
6 Cfg *ConfigSite
7 Dbpool db.DB
8 Storage storage.StorageServe
9 }
10
11 func (hc *HttpCtx) CreateCtx(prevCtx context.Context, subdomain string) context.Context {
12- loggerCtx := context.WithValue(prevCtx, ctxLoggerKey{}, hc.Logger)
13+ loggerCtx := context.WithValue(prevCtx, ctxLoggerKey{}, hc.Cfg.Logger)
14 subdomainCtx := context.WithValue(loggerCtx, ctxSubdomainKey{}, subdomain)
15 dbCtx := context.WithValue(subdomainCtx, ctxDBKey{}, hc.Dbpool)
16 storageCtx := context.WithValue(dbCtx, ctxStorageKey{}, hc.Storage)