From d59e36e00cc43ded6d78070fe05fb75b6ea524e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ufuktan=20Y=C4=B1ld=C4=B1r=C4=B1m?= <13807261+ufukty@users.noreply.github.com> Date: Thu, 11 Jun 2026 15:47:58 +0300 Subject: [PATCH 1/7] be/int/web/registration/reception: moves down. --- backend/cmd/api/main.go | 3 ++- backend/cmd/groups/main.go | 3 ++- backend/cmd/internal/main.go | 3 ++- backend/cmd/objectives/main.go | 3 ++- backend/cmd/pdp/main.go | 5 +++-- backend/cmd/profiles/main.go | 3 ++- backend/cmd/registration/main.go | 3 ++- backend/cmd/registry/main.go | 3 ++- backend/cmd/sessions/main.go | 3 ++- backend/cmd/tags/main.go | 3 ++- backend/cmd/users/main.go | 3 ++- backend/internal/web/{ => registration}/reception/agent.go | 0 .../internal/web/{ => registration}/reception/captured/rw.go | 0 .../web/{ => registration}/reception/captured/rw_test.go | 0 .../internal/web/{ => registration}/reception/middlewares.go | 0 .../web/{ => registration}/reception/receptionist.go | 4 ++-- .../{ => registration}/reception/summarizer/summarizer.go | 2 +- .../reception/summarizer/summarizer_test.go | 2 +- 18 files changed, 27 insertions(+), 16 deletions(-) rename backend/internal/web/{ => registration}/reception/agent.go (100%) rename backend/internal/web/{ => registration}/reception/captured/rw.go (100%) rename backend/internal/web/{ => registration}/reception/captured/rw_test.go (100%) rename backend/internal/web/{ => registration}/reception/middlewares.go (100%) rename backend/internal/web/{ => registration}/reception/receptionist.go (95%) rename backend/internal/web/{ => registration}/reception/summarizer/summarizer.go (96%) rename backend/internal/web/{ => registration}/reception/summarizer/summarizer_test.go (84%) diff --git a/backend/cmd/api/main.go b/backend/cmd/api/main.go index 94a991cd..43cc5717 100644 --- a/backend/cmd/api/main.go +++ b/backend/cmd/api/main.go @@ -3,11 +3,12 @@ package main import ( "fmt" "log" + registry "logbook/cmd/registry/client" "logbook/internal/startup" "logbook/internal/web/balancer" "logbook/internal/web/forwarder" - "logbook/internal/web/reception" + "logbook/internal/web/registration/reception" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" diff --git a/backend/cmd/groups/main.go b/backend/cmd/groups/main.go index 83324d85..4bb82f6c 100644 --- a/backend/cmd/groups/main.go +++ b/backend/cmd/groups/main.go @@ -3,13 +3,14 @@ package main import ( "context" "fmt" + "logbook/cmd/groups/app" "logbook/cmd/groups/endpoints" "logbook/cmd/groups/service" registry "logbook/cmd/registry/client" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/reception" + "logbook/internal/web/registration/reception" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" diff --git a/backend/cmd/internal/main.go b/backend/cmd/internal/main.go index 9fd6c974..a2aca572 100644 --- a/backend/cmd/internal/main.go +++ b/backend/cmd/internal/main.go @@ -3,9 +3,10 @@ package main import ( "fmt" "log" + "logbook/internal/startup" "logbook/internal/web/forwarder" - "logbook/internal/web/reception" + "logbook/internal/web/registration/reception" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/models" diff --git a/backend/cmd/objectives/main.go b/backend/cmd/objectives/main.go index c91671fd..29333094 100644 --- a/backend/cmd/objectives/main.go +++ b/backend/cmd/objectives/main.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log" + "logbook/cmd/objectives/app" "logbook/cmd/objectives/endpoints" "logbook/cmd/objectives/service" @@ -11,7 +12,7 @@ import ( sessions "logbook/cmd/sessions/client" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/reception" + "logbook/internal/web/registration/reception" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" diff --git a/backend/cmd/pdp/main.go b/backend/cmd/pdp/main.go index 5faeb485..03945fac 100644 --- a/backend/cmd/pdp/main.go +++ b/backend/cmd/pdp/main.go @@ -3,6 +3,8 @@ package main import ( "fmt" "log" + "os" + groups "logbook/cmd/groups/client" objectives "logbook/cmd/objectives/client" "logbook/cmd/pdp/decider" @@ -10,12 +12,11 @@ import ( registry "logbook/cmd/registry/client" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/reception" + "logbook/internal/web/registration/reception" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" "logbook/models" - "os" ) func Main() error { diff --git a/backend/cmd/profiles/main.go b/backend/cmd/profiles/main.go index b0235f8a..44d3b8c6 100644 --- a/backend/cmd/profiles/main.go +++ b/backend/cmd/profiles/main.go @@ -4,13 +4,14 @@ import ( "context" "fmt" "log" + "logbook/cmd/profiles/app" "logbook/cmd/profiles/endpoints" "logbook/cmd/profiles/service" registry "logbook/cmd/registry/client" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/reception" + "logbook/internal/web/registration/reception" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" diff --git a/backend/cmd/registration/main.go b/backend/cmd/registration/main.go index ec032ea0..d579f30d 100644 --- a/backend/cmd/registration/main.go +++ b/backend/cmd/registration/main.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log" + objectives "logbook/cmd/objectives/client" profiles "logbook/cmd/profiles/client" "logbook/cmd/registration/app" @@ -13,7 +14,7 @@ import ( sessions "logbook/cmd/sessions/client" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/reception" + "logbook/internal/web/registration/reception" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" diff --git a/backend/cmd/registry/main.go b/backend/cmd/registry/main.go index 443a49b3..37206f71 100644 --- a/backend/cmd/registry/main.go +++ b/backend/cmd/registry/main.go @@ -3,10 +3,11 @@ package main import ( "fmt" "log" + "logbook/cmd/registry/app" "logbook/cmd/registry/endpoints" "logbook/internal/startup" - "logbook/internal/web/reception" + "logbook/internal/web/registration/reception" "logbook/internal/web/router" ) diff --git a/backend/cmd/sessions/main.go b/backend/cmd/sessions/main.go index 2de16b96..2502ce80 100644 --- a/backend/cmd/sessions/main.go +++ b/backend/cmd/sessions/main.go @@ -4,13 +4,14 @@ import ( "context" "fmt" "log" + registry "logbook/cmd/registry/client" "logbook/cmd/sessions/app" "logbook/cmd/sessions/endpoints" "logbook/cmd/sessions/service" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/reception" + "logbook/internal/web/registration/reception" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" diff --git a/backend/cmd/tags/main.go b/backend/cmd/tags/main.go index 93a4efe6..d7633b36 100644 --- a/backend/cmd/tags/main.go +++ b/backend/cmd/tags/main.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log" + registry "logbook/cmd/registry/client" sessions "logbook/cmd/sessions/client" "logbook/cmd/tags/app" @@ -11,7 +12,7 @@ import ( "logbook/cmd/tags/service" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/reception" + "logbook/internal/web/registration/reception" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" diff --git a/backend/cmd/users/main.go b/backend/cmd/users/main.go index c4e35253..a3cb0a4b 100644 --- a/backend/cmd/users/main.go +++ b/backend/cmd/users/main.go @@ -4,13 +4,14 @@ import ( "context" "fmt" "log" + "logbook/cmd/profiles/app" "logbook/cmd/profiles/endpoints" "logbook/cmd/profiles/service" registry "logbook/cmd/registry/client" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/reception" + "logbook/internal/web/registration/reception" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" diff --git a/backend/internal/web/reception/agent.go b/backend/internal/web/registration/reception/agent.go similarity index 100% rename from backend/internal/web/reception/agent.go rename to backend/internal/web/registration/reception/agent.go diff --git a/backend/internal/web/reception/captured/rw.go b/backend/internal/web/registration/reception/captured/rw.go similarity index 100% rename from backend/internal/web/reception/captured/rw.go rename to backend/internal/web/registration/reception/captured/rw.go diff --git a/backend/internal/web/reception/captured/rw_test.go b/backend/internal/web/registration/reception/captured/rw_test.go similarity index 100% rename from backend/internal/web/reception/captured/rw_test.go rename to backend/internal/web/registration/reception/captured/rw_test.go diff --git a/backend/internal/web/reception/middlewares.go b/backend/internal/web/registration/reception/middlewares.go similarity index 100% rename from backend/internal/web/reception/middlewares.go rename to backend/internal/web/registration/reception/middlewares.go diff --git a/backend/internal/web/reception/receptionist.go b/backend/internal/web/registration/reception/receptionist.go similarity index 95% rename from backend/internal/web/reception/receptionist.go rename to backend/internal/web/registration/reception/receptionist.go index 59e1c116..d67d11e5 100644 --- a/backend/internal/web/reception/receptionist.go +++ b/backend/internal/web/registration/reception/receptionist.go @@ -18,8 +18,8 @@ import ( "logbook/config/deployment" "logbook/internal/logger" - "logbook/internal/web/reception/captured" - "logbook/internal/web/reception/summarizer" + "logbook/internal/web/registration/reception/captured" + "logbook/internal/web/registration/reception/summarizer" "logbook/models/columns" ) diff --git a/backend/internal/web/reception/summarizer/summarizer.go b/backend/internal/web/registration/reception/summarizer/summarizer.go similarity index 96% rename from backend/internal/web/reception/summarizer/summarizer.go rename to backend/internal/web/registration/reception/summarizer/summarizer.go index 7a3f6c58..d811b398 100644 --- a/backend/internal/web/reception/summarizer/summarizer.go +++ b/backend/internal/web/registration/reception/summarizer/summarizer.go @@ -5,7 +5,7 @@ import ( "net/http" "time" - "logbook/internal/web/reception/captured" + "logbook/internal/web/registration/reception/captured" ) type colorizer interface { diff --git a/backend/internal/web/reception/summarizer/summarizer_test.go b/backend/internal/web/registration/reception/summarizer/summarizer_test.go similarity index 84% rename from backend/internal/web/reception/summarizer/summarizer_test.go rename to backend/internal/web/registration/reception/summarizer/summarizer_test.go index 489e27f4..063c9f39 100644 --- a/backend/internal/web/reception/summarizer/summarizer_test.go +++ b/backend/internal/web/registration/reception/summarizer/summarizer_test.go @@ -5,7 +5,7 @@ import ( "net/http/httptest" "time" - "logbook/internal/web/reception/captured" + "logbook/internal/web/registration/reception/captured" ) func ExampleSummarizer_post() { From 79ed237037674046e03e2c72e75075d08876f117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ufuktan=20Y=C4=B1ld=C4=B1r=C4=B1m?= <13807261+ufukty@users.noreply.github.com> Date: Thu, 11 Jun 2026 15:52:56 +0300 Subject: [PATCH 2/7] be/int/web/registration: moves up the registration agent, splitting from receptionist and middlewares. --- backend/cmd/api/main.go | 4 ++-- backend/cmd/groups/main.go | 4 ++-- backend/cmd/internal/main.go | 4 ++-- backend/cmd/objectives/main.go | 4 ++-- backend/cmd/pdp/main.go | 4 ++-- backend/cmd/profiles/main.go | 4 ++-- backend/cmd/registration/main.go | 4 ++-- backend/cmd/registry/main.go | 4 ++-- backend/cmd/sessions/main.go | 4 ++-- backend/cmd/tags/main.go | 4 ++-- backend/cmd/users/main.go | 4 ++-- .../web/registration/{reception => }/agent.go | 24 ++++++++++--------- .../web/registration/reception/middlewares.go | 4 ++-- .../registration/reception/receptionist.go | 2 +- 14 files changed, 38 insertions(+), 36 deletions(-) rename backend/internal/web/registration/{reception => }/agent.go (70%) diff --git a/backend/cmd/api/main.go b/backend/cmd/api/main.go index 43cc5717..5338e89b 100644 --- a/backend/cmd/api/main.go +++ b/backend/cmd/api/main.go @@ -8,7 +8,7 @@ import ( "logbook/internal/startup" "logbook/internal/web/balancer" "logbook/internal/web/forwarder" - "logbook/internal/web/registration/reception" + "logbook/internal/web/registration" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" @@ -37,7 +37,7 @@ func Main() error { }, l) defer sc.Stop() - agent := reception.NewAgent(deplcfg, l) + agent := registration.NewAgent(deplcfg, l) err = agent.RegisterForwarders(map[models.Service]*forwarder.LoadBalancedReverseProxy{ models.Users: forwarder.New(sc.InstanceSource(models.Users), deplcfg, l), models.Objectives: forwarder.New(sc.InstanceSource(models.Objectives), deplcfg, l), diff --git a/backend/cmd/groups/main.go b/backend/cmd/groups/main.go index 4bb82f6c..e3f3ced4 100644 --- a/backend/cmd/groups/main.go +++ b/backend/cmd/groups/main.go @@ -10,7 +10,7 @@ import ( registry "logbook/cmd/registry/client" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/registration/reception" + "logbook/internal/web/registration" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" @@ -46,7 +46,7 @@ func Main() error { pub := endpoints.NewPublic(a, l) pri := endpoints.NewPrivate(a, l) - agent := reception.NewAgent(deplcfg, l) + agent := registration.NewAgent(deplcfg, l) err = agent.RegisterEndpoints(pub, pri) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) diff --git a/backend/cmd/internal/main.go b/backend/cmd/internal/main.go index a2aca572..1697883d 100644 --- a/backend/cmd/internal/main.go +++ b/backend/cmd/internal/main.go @@ -6,7 +6,7 @@ import ( "logbook/internal/startup" "logbook/internal/web/forwarder" - "logbook/internal/web/registration/reception" + "logbook/internal/web/registration" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/models" @@ -24,7 +24,7 @@ func Main() error { }, l) defer registrysd.Stop() - agent := reception.NewAgent(deplcfg, l) + agent := registration.NewAgent(deplcfg, l) err = agent.RegisterForwarders(map[models.Service]*forwarder.LoadBalancedReverseProxy{ models.Registry: forwarder.New(registrysd, deplcfg, l), }) diff --git a/backend/cmd/objectives/main.go b/backend/cmd/objectives/main.go index 29333094..cd079ee5 100644 --- a/backend/cmd/objectives/main.go +++ b/backend/cmd/objectives/main.go @@ -12,7 +12,7 @@ import ( sessions "logbook/cmd/sessions/client" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/registration/reception" + "logbook/internal/web/registration" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" @@ -48,7 +48,7 @@ func Main() error { pub := endpoints.NewPublic(a, sessions.NewClient(balancer.New(sc.InstanceSource(models.Sessions))), l) priv := endpoints.NewPrivate(a, l) - agent := reception.NewAgent(deplcfg, l) + agent := registration.NewAgent(deplcfg, l) err = agent.RegisterEndpoints(pub, priv) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) diff --git a/backend/cmd/pdp/main.go b/backend/cmd/pdp/main.go index 03945fac..187187ca 100644 --- a/backend/cmd/pdp/main.go +++ b/backend/cmd/pdp/main.go @@ -12,7 +12,7 @@ import ( registry "logbook/cmd/registry/client" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/registration/reception" + "logbook/internal/web/registration" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" @@ -44,7 +44,7 @@ func Main() error { objectives.NewClient(balancer.New(sc.InstanceSource(models.Objectives))), ) eps := endpoints.NewPrivate(d, l) - agent := reception.NewAgent(deplcfg, l) + agent := registration.NewAgent(deplcfg, l) err = agent.RegisterEndpoints(nil, eps) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) diff --git a/backend/cmd/profiles/main.go b/backend/cmd/profiles/main.go index 44d3b8c6..13b67425 100644 --- a/backend/cmd/profiles/main.go +++ b/backend/cmd/profiles/main.go @@ -11,7 +11,7 @@ import ( registry "logbook/cmd/registry/client" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/registration/reception" + "logbook/internal/web/registration" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" @@ -46,7 +46,7 @@ func Main() error { pri := endpoints.NewPrivate(a, l) - agent := reception.NewAgent(deplcfg, l) + agent := registration.NewAgent(deplcfg, l) err = agent.RegisterEndpoints(nil, pri) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) diff --git a/backend/cmd/registration/main.go b/backend/cmd/registration/main.go index d579f30d..47bc94d3 100644 --- a/backend/cmd/registration/main.go +++ b/backend/cmd/registration/main.go @@ -14,7 +14,7 @@ import ( sessions "logbook/cmd/sessions/client" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/registration/reception" + "logbook/internal/web/registration" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" @@ -51,7 +51,7 @@ func Main() error { Profiles: profiles.NewClient(balancer.New(sc.InstanceSource(models.Profiles))), } pub := endpoints.NewPublic(a, l) - agent := reception.NewAgent(deplcfg, l) + agent := registration.NewAgent(deplcfg, l) err = agent.RegisterEndpoints(pub, nil) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) diff --git a/backend/cmd/registry/main.go b/backend/cmd/registry/main.go index 37206f71..ff2809a1 100644 --- a/backend/cmd/registry/main.go +++ b/backend/cmd/registry/main.go @@ -7,7 +7,7 @@ import ( "logbook/cmd/registry/app" "logbook/cmd/registry/endpoints" "logbook/internal/startup" - "logbook/internal/web/registration/reception" + "logbook/internal/web/registration" "logbook/internal/web/router" ) @@ -21,7 +21,7 @@ func Main() error { defer a.Stop() e := endpoints.New(a, l) - agent := reception.NewAgent(deplycfg, l) + agent := registration.NewAgent(deplycfg, l) err = agent.RegisterEndpoints(nil, e) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) diff --git a/backend/cmd/sessions/main.go b/backend/cmd/sessions/main.go index 2502ce80..8ee4120c 100644 --- a/backend/cmd/sessions/main.go +++ b/backend/cmd/sessions/main.go @@ -11,7 +11,7 @@ import ( "logbook/cmd/sessions/service" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/registration/reception" + "logbook/internal/web/registration" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" @@ -47,7 +47,7 @@ func Main() error { pub := endpoints.NewPublic(a, l) pri := endpoints.NewPrivate(a, l) - agent := reception.NewAgent(deplcfg, l) + agent := registration.NewAgent(deplcfg, l) err = agent.RegisterEndpoints(pub, pri) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) diff --git a/backend/cmd/tags/main.go b/backend/cmd/tags/main.go index d7633b36..a090ed55 100644 --- a/backend/cmd/tags/main.go +++ b/backend/cmd/tags/main.go @@ -12,7 +12,7 @@ import ( "logbook/cmd/tags/service" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/registration/reception" + "logbook/internal/web/registration" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" @@ -50,7 +50,7 @@ func Main() error { a := app.New(pool, internalsd) e := endpoints.New(a, sessions, l) - agent := reception.NewAgent(deplcfg, l) + agent := registration.NewAgent(deplcfg, l) err = agent.RegisterEndpoints(e, nil) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) diff --git a/backend/cmd/users/main.go b/backend/cmd/users/main.go index a3cb0a4b..632d4e5c 100644 --- a/backend/cmd/users/main.go +++ b/backend/cmd/users/main.go @@ -11,7 +11,7 @@ import ( registry "logbook/cmd/registry/client" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/registration/reception" + "logbook/internal/web/registration" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" @@ -46,7 +46,7 @@ func Main() error { pri := endpoints.NewPrivate(a, l) - agent := reception.NewAgent(deplcfg, l) + agent := registration.NewAgent(deplcfg, l) err = agent.RegisterEndpoints(nil, pri) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) diff --git a/backend/internal/web/registration/reception/agent.go b/backend/internal/web/registration/agent.go similarity index 70% rename from backend/internal/web/registration/reception/agent.go rename to backend/internal/web/registration/agent.go index 12f5a440..f26c2b84 100644 --- a/backend/internal/web/registration/reception/agent.go +++ b/backend/internal/web/registration/agent.go @@ -1,13 +1,15 @@ -package reception +package registration import ( "fmt" + "net/http" + "net/url" + "logbook/config/deployment" "logbook/internal/logger" "logbook/internal/web/forwarder" + "logbook/internal/web/registration/reception" "logbook/models" - "net/http" - "net/url" "go.ufukty.com/gohandlers/pkg/gohandlers" ) @@ -51,8 +53,8 @@ func (ag *Agent) RegisterEndpoints(public, private Lister) error { if public != nil { for hn, info := range public.ListHandlers() { - c := newCors(info.Ref, origin, []string{info.Method}, corsheaders) - pl := newReceptionist(ag.deplcfg, ag.l.Sub(info.Path), c) + c := reception.NewCors(info.Ref, origin, []string{info.Method}, corsheaders) + pl := reception.New(ag.deplcfg, ag.l.Sub(info.Path), c) ag.l.Printf("registering: %s (%s, OPTIONS %s) -> %p\n", hn, info.Method, info.Path, pl) for _, method := range []string{info.Method, "OPTIONS"} { @@ -64,15 +66,15 @@ func (ag *Agent) RegisterEndpoints(public, private Lister) error { if private != nil { for hn, info := range private.ListHandlers() { - pl := newReceptionist(ag.deplcfg, ag.l.Sub(info.Path), info.Ref) + pl := reception.New(ag.deplcfg, ag.l.Sub(info.Path), info.Ref) pattern := fmt.Sprintf("%s %s", info.Method, info.Path) ag.l.Printf("registering: %s (%s) -> %p\n", hn, pattern, pl) ag.r.Handle(pattern, pl) } } - ag.r.Handle("GET /ping", newReceptionist(ag.deplcfg, ag.l.Sub("ping"), http.HandlerFunc(pong))) - ag.r.Handle("GET /", newReceptionist(ag.deplcfg, ag.l.Sub("not-found"), http.HandlerFunc(http.NotFound))) + ag.r.Handle("GET /ping", reception.New(ag.deplcfg, ag.l.Sub("ping"), http.HandlerFunc(reception.Pong))) + ag.r.Handle("GET /", reception.New(ag.deplcfg, ag.l.Sub("not-found"), http.HandlerFunc(http.NotFound))) return nil } @@ -81,11 +83,11 @@ func (ag *Agent) RegisterForwarders(fwds map[models.Service]*forwarder.LoadBalan for addr, fwd := range fwds { ag.l.Printf("registering forwarder for: %s -> %p\n", addr, fwd) l := ag.l.Sub(fmt.Sprintf("strip-prefix(%s)", addr)) - ag.r.Handle(string(addr)+"/", newReceptionist(ag.deplcfg, l, http.StripPrefix(string(addr), fwd))) + ag.r.Handle(string(addr)+"/", reception.New(ag.deplcfg, l, http.StripPrefix(string(addr), fwd))) } - ag.r.Handle("/ping", newReceptionist(ag.deplcfg, ag.l.Sub("ping"), http.HandlerFunc(pong))) - ag.r.Handle("/", newReceptionist(ag.deplcfg, ag.l.Sub("not-found"), http.HandlerFunc(http.NotFound))) + ag.r.Handle("/ping", reception.New(ag.deplcfg, ag.l.Sub("ping"), http.HandlerFunc(reception.Pong))) + ag.r.Handle("/", reception.New(ag.deplcfg, ag.l.Sub("not-found"), http.HandlerFunc(http.NotFound))) return nil } diff --git a/backend/internal/web/registration/reception/middlewares.go b/backend/internal/web/registration/reception/middlewares.go index 53c8c7ec..829d448e 100644 --- a/backend/internal/web/registration/reception/middlewares.go +++ b/backend/internal/web/registration/reception/middlewares.go @@ -13,7 +13,7 @@ type cors struct { next http.HandlerFunc } -func newCors(next http.HandlerFunc, origin string, methods, headers []string) *cors { +func NewCors(next http.HandlerFunc, origin string, methods, headers []string) *cors { methods = append(methods, "OPTIONS") return &cors{ origin: origin, @@ -38,7 +38,7 @@ func (c *cors) ServeHTTP(w http.ResponseWriter, r *http.Request) { c.next(w, r) } -func pong(w http.ResponseWriter, r *http.Request) { +func Pong(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "pong") w.WriteHeader(http.StatusOK) } diff --git a/backend/internal/web/registration/reception/receptionist.go b/backend/internal/web/registration/reception/receptionist.go index d67d11e5..44519fa3 100644 --- a/backend/internal/web/registration/reception/receptionist.go +++ b/backend/internal/web/registration/reception/receptionist.go @@ -50,7 +50,7 @@ type receptionist struct { h http.Handler } -func newReceptionist(c *deployment.Config, l *logger.Logger, h http.Handler) *receptionist { +func New(c *deployment.Config, l *logger.Logger, h http.Handler) *receptionist { return &receptionist{ c: c, s: summarizer.New(c.Environment == "local"), From b585d632f8cabe6257f92bfda8b7ad826a9c9708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ufuktan=20Y=C4=B1ld=C4=B1r=C4=B1m?= <13807261+ufukty@users.noreply.github.com> Date: Thu, 11 Jun 2026 15:53:23 +0300 Subject: [PATCH 3/7] be/int/web/registration: removes unused. --- backend/internal/web/registration/agent.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/backend/internal/web/registration/agent.go b/backend/internal/web/registration/agent.go index f26c2b84..878832bb 100644 --- a/backend/internal/web/registration/agent.go +++ b/backend/internal/web/registration/agent.go @@ -33,12 +33,6 @@ func (a *Agent) Mux() *http.ServeMux { return a.r } -type HandlerInfo struct { - Method string - Path string - Ref http.HandlerFunc -} - type Lister interface { ListHandlers() map[string]gohandlers.HandlerInfo } From e3b43e26dde216225389fc431e5e2dc1be70c45f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ufuktan=20Y=C4=B1ld=C4=B1r=C4=B1m?= <13807261+ufukty@users.noreply.github.com> Date: Fri, 12 Jun 2026 16:23:27 +0300 Subject: [PATCH 4/7] int/web/register: renames package. --- backend/cmd/api/main.go | 4 ++-- backend/cmd/groups/main.go | 4 ++-- backend/cmd/internal/main.go | 4 ++-- backend/cmd/objectives/main.go | 4 ++-- backend/cmd/pdp/main.go | 4 ++-- backend/cmd/profiles/main.go | 4 ++-- backend/cmd/registration/main.go | 4 ++-- backend/cmd/registry/main.go | 4 ++-- backend/cmd/sessions/main.go | 4 ++-- backend/cmd/tags/main.go | 4 ++-- backend/cmd/users/main.go | 4 ++-- backend/internal/web/{registration => register}/agent.go | 2 +- 12 files changed, 23 insertions(+), 23 deletions(-) rename backend/internal/web/{registration => register}/agent.go (99%) diff --git a/backend/cmd/api/main.go b/backend/cmd/api/main.go index 5338e89b..4720b51f 100644 --- a/backend/cmd/api/main.go +++ b/backend/cmd/api/main.go @@ -8,7 +8,7 @@ import ( "logbook/internal/startup" "logbook/internal/web/balancer" "logbook/internal/web/forwarder" - "logbook/internal/web/registration" + "logbook/internal/web/register" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" @@ -37,7 +37,7 @@ func Main() error { }, l) defer sc.Stop() - agent := registration.NewAgent(deplcfg, l) + agent := register.NewAgent(deplcfg, l) err = agent.RegisterForwarders(map[models.Service]*forwarder.LoadBalancedReverseProxy{ models.Users: forwarder.New(sc.InstanceSource(models.Users), deplcfg, l), models.Objectives: forwarder.New(sc.InstanceSource(models.Objectives), deplcfg, l), diff --git a/backend/cmd/groups/main.go b/backend/cmd/groups/main.go index e3f3ced4..3852ae3f 100644 --- a/backend/cmd/groups/main.go +++ b/backend/cmd/groups/main.go @@ -10,7 +10,7 @@ import ( registry "logbook/cmd/registry/client" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/registration" + "logbook/internal/web/register" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" @@ -46,7 +46,7 @@ func Main() error { pub := endpoints.NewPublic(a, l) pri := endpoints.NewPrivate(a, l) - agent := registration.NewAgent(deplcfg, l) + agent := register.NewAgent(deplcfg, l) err = agent.RegisterEndpoints(pub, pri) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) diff --git a/backend/cmd/internal/main.go b/backend/cmd/internal/main.go index 1697883d..98f90d30 100644 --- a/backend/cmd/internal/main.go +++ b/backend/cmd/internal/main.go @@ -6,7 +6,7 @@ import ( "logbook/internal/startup" "logbook/internal/web/forwarder" - "logbook/internal/web/registration" + "logbook/internal/web/register" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/models" @@ -24,7 +24,7 @@ func Main() error { }, l) defer registrysd.Stop() - agent := registration.NewAgent(deplcfg, l) + agent := register.NewAgent(deplcfg, l) err = agent.RegisterForwarders(map[models.Service]*forwarder.LoadBalancedReverseProxy{ models.Registry: forwarder.New(registrysd, deplcfg, l), }) diff --git a/backend/cmd/objectives/main.go b/backend/cmd/objectives/main.go index cd079ee5..a05956f2 100644 --- a/backend/cmd/objectives/main.go +++ b/backend/cmd/objectives/main.go @@ -12,7 +12,7 @@ import ( sessions "logbook/cmd/sessions/client" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/registration" + "logbook/internal/web/register" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" @@ -48,7 +48,7 @@ func Main() error { pub := endpoints.NewPublic(a, sessions.NewClient(balancer.New(sc.InstanceSource(models.Sessions))), l) priv := endpoints.NewPrivate(a, l) - agent := registration.NewAgent(deplcfg, l) + agent := register.NewAgent(deplcfg, l) err = agent.RegisterEndpoints(pub, priv) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) diff --git a/backend/cmd/pdp/main.go b/backend/cmd/pdp/main.go index 187187ca..84354e9f 100644 --- a/backend/cmd/pdp/main.go +++ b/backend/cmd/pdp/main.go @@ -12,7 +12,7 @@ import ( registry "logbook/cmd/registry/client" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/registration" + "logbook/internal/web/register" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" @@ -44,7 +44,7 @@ func Main() error { objectives.NewClient(balancer.New(sc.InstanceSource(models.Objectives))), ) eps := endpoints.NewPrivate(d, l) - agent := registration.NewAgent(deplcfg, l) + agent := register.NewAgent(deplcfg, l) err = agent.RegisterEndpoints(nil, eps) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) diff --git a/backend/cmd/profiles/main.go b/backend/cmd/profiles/main.go index 13b67425..229b390b 100644 --- a/backend/cmd/profiles/main.go +++ b/backend/cmd/profiles/main.go @@ -11,7 +11,7 @@ import ( registry "logbook/cmd/registry/client" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/registration" + "logbook/internal/web/register" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" @@ -46,7 +46,7 @@ func Main() error { pri := endpoints.NewPrivate(a, l) - agent := registration.NewAgent(deplcfg, l) + agent := register.NewAgent(deplcfg, l) err = agent.RegisterEndpoints(nil, pri) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) diff --git a/backend/cmd/registration/main.go b/backend/cmd/registration/main.go index 47bc94d3..ea934660 100644 --- a/backend/cmd/registration/main.go +++ b/backend/cmd/registration/main.go @@ -14,7 +14,7 @@ import ( sessions "logbook/cmd/sessions/client" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/registration" + "logbook/internal/web/register" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" @@ -51,7 +51,7 @@ func Main() error { Profiles: profiles.NewClient(balancer.New(sc.InstanceSource(models.Profiles))), } pub := endpoints.NewPublic(a, l) - agent := registration.NewAgent(deplcfg, l) + agent := register.NewAgent(deplcfg, l) err = agent.RegisterEndpoints(pub, nil) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) diff --git a/backend/cmd/registry/main.go b/backend/cmd/registry/main.go index ff2809a1..c2b4f79e 100644 --- a/backend/cmd/registry/main.go +++ b/backend/cmd/registry/main.go @@ -7,7 +7,7 @@ import ( "logbook/cmd/registry/app" "logbook/cmd/registry/endpoints" "logbook/internal/startup" - "logbook/internal/web/registration" + "logbook/internal/web/register" "logbook/internal/web/router" ) @@ -21,7 +21,7 @@ func Main() error { defer a.Stop() e := endpoints.New(a, l) - agent := registration.NewAgent(deplycfg, l) + agent := register.NewAgent(deplycfg, l) err = agent.RegisterEndpoints(nil, e) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) diff --git a/backend/cmd/sessions/main.go b/backend/cmd/sessions/main.go index 8ee4120c..1aa3353e 100644 --- a/backend/cmd/sessions/main.go +++ b/backend/cmd/sessions/main.go @@ -11,7 +11,7 @@ import ( "logbook/cmd/sessions/service" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/registration" + "logbook/internal/web/register" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" @@ -47,7 +47,7 @@ func Main() error { pub := endpoints.NewPublic(a, l) pri := endpoints.NewPrivate(a, l) - agent := registration.NewAgent(deplcfg, l) + agent := register.NewAgent(deplcfg, l) err = agent.RegisterEndpoints(pub, pri) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) diff --git a/backend/cmd/tags/main.go b/backend/cmd/tags/main.go index a090ed55..3d1dd4dc 100644 --- a/backend/cmd/tags/main.go +++ b/backend/cmd/tags/main.go @@ -12,7 +12,7 @@ import ( "logbook/cmd/tags/service" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/registration" + "logbook/internal/web/register" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" @@ -50,7 +50,7 @@ func Main() error { a := app.New(pool, internalsd) e := endpoints.New(a, sessions, l) - agent := registration.NewAgent(deplcfg, l) + agent := register.NewAgent(deplcfg, l) err = agent.RegisterEndpoints(e, nil) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) diff --git a/backend/cmd/users/main.go b/backend/cmd/users/main.go index 632d4e5c..cec8e190 100644 --- a/backend/cmd/users/main.go +++ b/backend/cmd/users/main.go @@ -11,7 +11,7 @@ import ( registry "logbook/cmd/registry/client" "logbook/internal/startup" "logbook/internal/web/balancer" - "logbook/internal/web/registration" + "logbook/internal/web/register" "logbook/internal/web/registryfile" "logbook/internal/web/router" "logbook/internal/web/sidecar" @@ -46,7 +46,7 @@ func Main() error { pri := endpoints.NewPrivate(a, l) - agent := registration.NewAgent(deplcfg, l) + agent := register.NewAgent(deplcfg, l) err = agent.RegisterEndpoints(nil, pri) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) diff --git a/backend/internal/web/registration/agent.go b/backend/internal/web/register/agent.go similarity index 99% rename from backend/internal/web/registration/agent.go rename to backend/internal/web/register/agent.go index 878832bb..4a2045f0 100644 --- a/backend/internal/web/registration/agent.go +++ b/backend/internal/web/register/agent.go @@ -1,4 +1,4 @@ -package registration +package register import ( "fmt" From 2ade27c09b55c3d25c7286527cc243a2341b08ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ufuktan=20Y=C4=B1ld=C4=B1r=C4=B1m?= <13807261+ufukty@users.noreply.github.com> Date: Fri, 12 Jun 2026 16:42:33 +0300 Subject: [PATCH 5/7] be/int/web/register: refactors for clarity. breaks down the dependency struct that were initially created to share common dependencies for more complex future uses. --- backend/cmd/api/main.go | 5 +- backend/cmd/groups/main.go | 5 +- backend/cmd/internal/main.go | 9 +--- backend/cmd/objectives/main.go | 5 +- backend/cmd/pdp/main.go | 5 +- backend/cmd/profiles/main.go | 5 +- backend/cmd/registration/main.go | 5 +- backend/cmd/registry/main.go | 13 +++-- backend/cmd/sessions/main.go | 5 +- backend/cmd/tags/main.go | 5 +- backend/cmd/users/main.go | 5 +- backend/internal/web/register/agent.go | 66 +++++++++++--------------- 12 files changed, 54 insertions(+), 79 deletions(-) diff --git a/backend/cmd/api/main.go b/backend/cmd/api/main.go index 4720b51f..1caaaaf7 100644 --- a/backend/cmd/api/main.go +++ b/backend/cmd/api/main.go @@ -37,8 +37,7 @@ func Main() error { }, l) defer sc.Stop() - agent := register.NewAgent(deplcfg, l) - err = agent.RegisterForwarders(map[models.Service]*forwarder.LoadBalancedReverseProxy{ + r, err := register.RegisterForwarders(deplcfg, l, map[models.Service]*forwarder.LoadBalancedReverseProxy{ models.Users: forwarder.New(sc.InstanceSource(models.Users), deplcfg, l), models.Objectives: forwarder.New(sc.InstanceSource(models.Objectives), deplcfg, l), models.Profiles: forwarder.New(sc.InstanceSource(models.Profiles), deplcfg, l), @@ -51,7 +50,7 @@ func Main() error { err = router.StartServer(router.ServerParameters{ Port: deplcfg.Ports.Gateway, Router: deplcfg.Router, - ServeMux: agent.Mux(), + ServeMux: r, TlsCrt: args.TlsCertificate, TlsKey: args.TlsKey, }, l) diff --git a/backend/cmd/groups/main.go b/backend/cmd/groups/main.go index 3852ae3f..06350718 100644 --- a/backend/cmd/groups/main.go +++ b/backend/cmd/groups/main.go @@ -46,8 +46,7 @@ func Main() error { pub := endpoints.NewPublic(a, l) pri := endpoints.NewPrivate(a, l) - agent := register.NewAgent(deplcfg, l) - err = agent.RegisterEndpoints(pub, pri) + r, err := register.RegisterEndpoints(deplcfg, l, pub, pri) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) } @@ -56,7 +55,7 @@ func Main() error { Address: args.PrivateNetworkIp, Port: deplcfg.Ports.Objectives, Router: deplcfg.Router, - ServeMux: agent.Mux(), + ServeMux: r, Service: models.Groups, Sidecar: sc, TlsCrt: args.TlsCertificate, diff --git a/backend/cmd/internal/main.go b/backend/cmd/internal/main.go index 98f90d30..b15a3139 100644 --- a/backend/cmd/internal/main.go +++ b/backend/cmd/internal/main.go @@ -24,22 +24,17 @@ func Main() error { }, l) defer registrysd.Stop() - agent := register.NewAgent(deplcfg, l) - err = agent.RegisterForwarders(map[models.Service]*forwarder.LoadBalancedReverseProxy{ + r, err := register.RegisterForwarders(deplcfg, l, map[models.Service]*forwarder.LoadBalancedReverseProxy{ models.Registry: forwarder.New(registrysd, deplcfg, l), }) if err != nil { return fmt.Errorf("agent.RegisterForwarders: %w", err) } - // err = agent.RegisterCommonalities() - // if err != nil { - // return fmt.Errorf("agent.RegisterCommonalities: %w", err) - // } router.StartServer(router.ServerParameters{ Router: deplcfg.Router, Port: deplcfg.Ports.Internal, - ServeMux: agent.Mux(), + ServeMux: r, TlsCrt: args.TlsCertificate, TlsKey: args.TlsKey, }, l) diff --git a/backend/cmd/objectives/main.go b/backend/cmd/objectives/main.go index a05956f2..26d15b2d 100644 --- a/backend/cmd/objectives/main.go +++ b/backend/cmd/objectives/main.go @@ -48,8 +48,7 @@ func Main() error { pub := endpoints.NewPublic(a, sessions.NewClient(balancer.New(sc.InstanceSource(models.Sessions))), l) priv := endpoints.NewPrivate(a, l) - agent := register.NewAgent(deplcfg, l) - err = agent.RegisterEndpoints(pub, priv) + r, err := register.RegisterEndpoints(deplcfg, l, pub, priv) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) } @@ -58,7 +57,7 @@ func Main() error { Address: args.PrivateNetworkIp, Port: deplcfg.Ports.Objectives, Router: deplcfg.Router, - ServeMux: agent.Mux(), + ServeMux: r, Service: models.Objectives, Sidecar: sc, TlsCrt: args.TlsCertificate, diff --git a/backend/cmd/pdp/main.go b/backend/cmd/pdp/main.go index 84354e9f..9afa7b7d 100644 --- a/backend/cmd/pdp/main.go +++ b/backend/cmd/pdp/main.go @@ -44,8 +44,7 @@ func Main() error { objectives.NewClient(balancer.New(sc.InstanceSource(models.Objectives))), ) eps := endpoints.NewPrivate(d, l) - agent := register.NewAgent(deplcfg, l) - err = agent.RegisterEndpoints(nil, eps) + r, err := register.RegisterEndpoints(deplcfg, l, nil, eps) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) } @@ -56,7 +55,7 @@ func Main() error { Port: deplcfg.Ports.Pdp, Router: deplcfg.Router, Service: models.Pdp, - ServeMux: agent.Mux(), + ServeMux: r, Sidecar: sc, TlsCrt: args.TlsCertificate, TlsKey: args.TlsKey, diff --git a/backend/cmd/profiles/main.go b/backend/cmd/profiles/main.go index 229b390b..7bb7b607 100644 --- a/backend/cmd/profiles/main.go +++ b/backend/cmd/profiles/main.go @@ -46,8 +46,7 @@ func Main() error { pri := endpoints.NewPrivate(a, l) - agent := register.NewAgent(deplcfg, l) - err = agent.RegisterEndpoints(nil, pri) + r, err := register.RegisterEndpoints(deplcfg, l, nil, pri) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) } @@ -58,7 +57,7 @@ func Main() error { Port: deplcfg.Ports.Profiles, Router: deplcfg.Router, Service: models.Profiles, - ServeMux: agent.Mux(), + ServeMux: r, Sidecar: sc, TlsCrt: args.TlsCertificate, TlsKey: args.TlsKey, diff --git a/backend/cmd/registration/main.go b/backend/cmd/registration/main.go index ea934660..19384fdb 100644 --- a/backend/cmd/registration/main.go +++ b/backend/cmd/registration/main.go @@ -51,8 +51,7 @@ func Main() error { Profiles: profiles.NewClient(balancer.New(sc.InstanceSource(models.Profiles))), } pub := endpoints.NewPublic(a, l) - agent := register.NewAgent(deplcfg, l) - err = agent.RegisterEndpoints(pub, nil) + r, err := register.RegisterEndpoints(deplcfg, l, pub, nil) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) } @@ -63,7 +62,7 @@ func Main() error { Port: deplcfg.Ports.Registration, Router: deplcfg.Router, Service: models.Registration, - ServeMux: agent.Mux(), + ServeMux: r, Sidecar: sc, TlsCrt: args.TlsCertificate, TlsKey: args.TlsKey, diff --git a/backend/cmd/registry/main.go b/backend/cmd/registry/main.go index c2b4f79e..7aa8c40c 100644 --- a/backend/cmd/registry/main.go +++ b/backend/cmd/registry/main.go @@ -12,25 +12,24 @@ import ( ) func Main() error { - l, args, deplycfg, err := startup.Service("registry") + l, args, deplcfg, err := startup.Service("registry") if err != nil { return fmt.Errorf("reading config: %w", err) } - a := app.New(deplycfg, l) + a := app.New(deplcfg, l) defer a.Stop() e := endpoints.New(a, l) - agent := register.NewAgent(deplycfg, l) - err = agent.RegisterEndpoints(nil, e) + r, err := register.RegisterEndpoints(deplcfg, l, nil, e) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) } err = router.StartServer(router.ServerParameters{ - Port: deplycfg.Ports.Registry, - Router: deplycfg.Router, - ServeMux: agent.Mux(), + Port: deplcfg.Ports.Registry, + Router: deplcfg.Router, + ServeMux: r, TlsCrt: args.TlsCertificate, TlsKey: args.TlsKey, }, l) diff --git a/backend/cmd/sessions/main.go b/backend/cmd/sessions/main.go index 1aa3353e..8f932dc7 100644 --- a/backend/cmd/sessions/main.go +++ b/backend/cmd/sessions/main.go @@ -47,8 +47,7 @@ func Main() error { pub := endpoints.NewPublic(a, l) pri := endpoints.NewPrivate(a, l) - agent := register.NewAgent(deplcfg, l) - err = agent.RegisterEndpoints(pub, pri) + r, err := register.RegisterEndpoints(deplcfg, l, pub, pri) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) } @@ -59,7 +58,7 @@ func Main() error { Port: deplcfg.Ports.Sessions, Router: deplcfg.Router, Service: models.Sessions, - ServeMux: agent.Mux(), + ServeMux: r, Sidecar: sc, TlsCrt: args.TlsCertificate, TlsKey: args.TlsKey, diff --git a/backend/cmd/tags/main.go b/backend/cmd/tags/main.go index 3d1dd4dc..e98b3310 100644 --- a/backend/cmd/tags/main.go +++ b/backend/cmd/tags/main.go @@ -50,8 +50,7 @@ func Main() error { a := app.New(pool, internalsd) e := endpoints.New(a, sessions, l) - agent := register.NewAgent(deplcfg, l) - err = agent.RegisterEndpoints(e, nil) + r, err := register.RegisterEndpoints(deplcfg, l, e, nil) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) } @@ -65,7 +64,7 @@ func Main() error { Sidecar: sc, TlsCrt: args.TlsCertificate, TlsKey: args.TlsKey, - ServeMux: agent.Mux(), + ServeMux: r, }, l) if err != nil { return fmt.Errorf("router.StartServer: %w", err) diff --git a/backend/cmd/users/main.go b/backend/cmd/users/main.go index cec8e190..8a46d879 100644 --- a/backend/cmd/users/main.go +++ b/backend/cmd/users/main.go @@ -46,8 +46,7 @@ func Main() error { pri := endpoints.NewPrivate(a, l) - agent := register.NewAgent(deplcfg, l) - err = agent.RegisterEndpoints(nil, pri) + r, err := register.RegisterEndpoints(deplcfg, l, nil, pri) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) } @@ -58,7 +57,7 @@ func Main() error { Port: deplcfg.Ports.Users, Router: deplcfg.Router, Service: models.Users, - ServeMux: agent.Mux(), + ServeMux: r, Sidecar: sc, TlsCrt: args.TlsCertificate, TlsKey: args.TlsKey, diff --git a/backend/internal/web/register/agent.go b/backend/internal/web/register/agent.go index 4a2045f0..f00afcbd 100644 --- a/backend/internal/web/register/agent.go +++ b/backend/internal/web/register/agent.go @@ -14,74 +14,64 @@ import ( "go.ufukty.com/gohandlers/pkg/gohandlers" ) -// [Agent] is the registration Agent which helps services, and gateways to register their handlers and forwarders appropriately -type Agent struct { - deplcfg *deployment.Config - r *http.ServeMux - l *logger.Logger +type Lister interface { + ListHandlers() map[string]gohandlers.HandlerInfo } -func NewAgent(deplcfg *deployment.Config, l *logger.Logger) *Agent { - return &Agent{ - deplcfg: deplcfg, - r: http.NewServeMux(), - l: l.Sub("agent"), - } +func debug(c *deployment.Config, l *logger.Logger, r *http.ServeMux) { + r.Handle("GET /ping", reception.New(c, l.Sub("ping"), http.HandlerFunc(reception.Pong))) + r.Handle("GET /", reception.New(c, l.Sub("not-found"), http.HandlerFunc(http.NotFound))) } -func (a *Agent) Mux() *http.ServeMux { - return a.r -} +func RegisterEndpoints(c *deployment.Config, l *logger.Logger, public, private Lister) (*http.ServeMux, error) { + r := http.NewServeMux() + l = l.Sub("register") -type Lister interface { - ListHandlers() map[string]gohandlers.HandlerInfo -} - -func (ag *Agent) RegisterEndpoints(public, private Lister) error { - origin, err := url.JoinPath(ag.deplcfg.Router.Cors.AllowOrigin) + origin, err := url.JoinPath(c.Router.Cors.AllowOrigin) if err != nil { - return fmt.Errorf("url.JoinPath: %w", err) + return nil, fmt.Errorf("url.JoinPath: %w", err) } corsheaders := []string{"Authorization", "Content-Type"} if public != nil { for hn, info := range public.ListHandlers() { - c := reception.NewCors(info.Ref, origin, []string{info.Method}, corsheaders) - pl := reception.New(ag.deplcfg, ag.l.Sub(info.Path), c) + cors := reception.NewCors(info.Ref, origin, []string{info.Method}, corsheaders) + pl := reception.New(c, l.Sub(info.Path), cors) - ag.l.Printf("registering: %s (%s, OPTIONS %s) -> %p\n", hn, info.Method, info.Path, pl) + l.Printf("registering: %s (%s, OPTIONS %s) -> %p\n", hn, info.Method, info.Path, pl) for _, method := range []string{info.Method, "OPTIONS"} { pattern := fmt.Sprintf("%s %s", method, info.Path) - ag.r.Handle(pattern, pl) + r.Handle(pattern, pl) } } } if private != nil { for hn, info := range private.ListHandlers() { - pl := reception.New(ag.deplcfg, ag.l.Sub(info.Path), info.Ref) + pl := reception.New(c, l.Sub(info.Path), info.Ref) pattern := fmt.Sprintf("%s %s", info.Method, info.Path) - ag.l.Printf("registering: %s (%s) -> %p\n", hn, pattern, pl) - ag.r.Handle(pattern, pl) + l.Printf("registering: %s (%s) -> %p\n", hn, pattern, pl) + r.Handle(pattern, pl) } } - ag.r.Handle("GET /ping", reception.New(ag.deplcfg, ag.l.Sub("ping"), http.HandlerFunc(reception.Pong))) - ag.r.Handle("GET /", reception.New(ag.deplcfg, ag.l.Sub("not-found"), http.HandlerFunc(http.NotFound))) + debug(c, l, r) - return nil + return r, nil } -func (ag *Agent) RegisterForwarders(fwds map[models.Service]*forwarder.LoadBalancedReverseProxy) error { +func RegisterForwarders(c *deployment.Config, l *logger.Logger, fwds map[models.Service]*forwarder.LoadBalancedReverseProxy) (*http.ServeMux, error) { + r := http.NewServeMux() + l = l.Sub("register") + for addr, fwd := range fwds { - ag.l.Printf("registering forwarder for: %s -> %p\n", addr, fwd) - l := ag.l.Sub(fmt.Sprintf("strip-prefix(%s)", addr)) - ag.r.Handle(string(addr)+"/", reception.New(ag.deplcfg, l, http.StripPrefix(string(addr), fwd))) + l.Printf("registering forwarder for: %s -> %p\n", addr, fwd) + l := l.Sub(fmt.Sprintf("strip-prefix(%s)", addr)) + r.Handle(string(addr)+"/", reception.New(c, l, http.StripPrefix(string(addr), fwd))) } - ag.r.Handle("/ping", reception.New(ag.deplcfg, ag.l.Sub("ping"), http.HandlerFunc(reception.Pong))) - ag.r.Handle("/", reception.New(ag.deplcfg, ag.l.Sub("not-found"), http.HandlerFunc(http.NotFound))) + debug(c, l, r) - return nil + return r, nil } From 82b86cbbec9f5ed41ec22ffb8b8c134c9308d38f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ufuktan=20Y=C4=B1ld=C4=B1r=C4=B1m?= <13807261+ufukty@users.noreply.github.com> Date: Fri, 12 Jun 2026 16:44:26 +0300 Subject: [PATCH 6/7] be/int/web/register: renames registerers for import symbol clarity. --- backend/cmd/api/main.go | 2 +- backend/cmd/groups/main.go | 2 +- backend/cmd/internal/main.go | 2 +- backend/cmd/objectives/main.go | 2 +- backend/cmd/pdp/main.go | 2 +- backend/cmd/profiles/main.go | 2 +- backend/cmd/registration/main.go | 2 +- backend/cmd/registry/main.go | 2 +- backend/cmd/sessions/main.go | 2 +- backend/cmd/tags/main.go | 2 +- backend/cmd/users/main.go | 2 +- backend/internal/web/register/agent.go | 5 +++-- 12 files changed, 14 insertions(+), 13 deletions(-) diff --git a/backend/cmd/api/main.go b/backend/cmd/api/main.go index 1caaaaf7..39df4ef2 100644 --- a/backend/cmd/api/main.go +++ b/backend/cmd/api/main.go @@ -37,7 +37,7 @@ func Main() error { }, l) defer sc.Stop() - r, err := register.RegisterForwarders(deplcfg, l, map[models.Service]*forwarder.LoadBalancedReverseProxy{ + r, err := register.Forwarders(deplcfg, l, map[models.Service]*forwarder.LoadBalancedReverseProxy{ models.Users: forwarder.New(sc.InstanceSource(models.Users), deplcfg, l), models.Objectives: forwarder.New(sc.InstanceSource(models.Objectives), deplcfg, l), models.Profiles: forwarder.New(sc.InstanceSource(models.Profiles), deplcfg, l), diff --git a/backend/cmd/groups/main.go b/backend/cmd/groups/main.go index 06350718..94f9d2ef 100644 --- a/backend/cmd/groups/main.go +++ b/backend/cmd/groups/main.go @@ -46,7 +46,7 @@ func Main() error { pub := endpoints.NewPublic(a, l) pri := endpoints.NewPrivate(a, l) - r, err := register.RegisterEndpoints(deplcfg, l, pub, pri) + r, err := register.Endpoints(deplcfg, l, pub, pri) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) } diff --git a/backend/cmd/internal/main.go b/backend/cmd/internal/main.go index b15a3139..5a5c625d 100644 --- a/backend/cmd/internal/main.go +++ b/backend/cmd/internal/main.go @@ -24,7 +24,7 @@ func Main() error { }, l) defer registrysd.Stop() - r, err := register.RegisterForwarders(deplcfg, l, map[models.Service]*forwarder.LoadBalancedReverseProxy{ + r, err := register.Forwarders(deplcfg, l, map[models.Service]*forwarder.LoadBalancedReverseProxy{ models.Registry: forwarder.New(registrysd, deplcfg, l), }) if err != nil { diff --git a/backend/cmd/objectives/main.go b/backend/cmd/objectives/main.go index 26d15b2d..50234d74 100644 --- a/backend/cmd/objectives/main.go +++ b/backend/cmd/objectives/main.go @@ -48,7 +48,7 @@ func Main() error { pub := endpoints.NewPublic(a, sessions.NewClient(balancer.New(sc.InstanceSource(models.Sessions))), l) priv := endpoints.NewPrivate(a, l) - r, err := register.RegisterEndpoints(deplcfg, l, pub, priv) + r, err := register.Endpoints(deplcfg, l, pub, priv) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) } diff --git a/backend/cmd/pdp/main.go b/backend/cmd/pdp/main.go index 9afa7b7d..cf04ef2e 100644 --- a/backend/cmd/pdp/main.go +++ b/backend/cmd/pdp/main.go @@ -44,7 +44,7 @@ func Main() error { objectives.NewClient(balancer.New(sc.InstanceSource(models.Objectives))), ) eps := endpoints.NewPrivate(d, l) - r, err := register.RegisterEndpoints(deplcfg, l, nil, eps) + r, err := register.Endpoints(deplcfg, l, nil, eps) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) } diff --git a/backend/cmd/profiles/main.go b/backend/cmd/profiles/main.go index 7bb7b607..28b4c759 100644 --- a/backend/cmd/profiles/main.go +++ b/backend/cmd/profiles/main.go @@ -46,7 +46,7 @@ func Main() error { pri := endpoints.NewPrivate(a, l) - r, err := register.RegisterEndpoints(deplcfg, l, nil, pri) + r, err := register.Endpoints(deplcfg, l, nil, pri) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) } diff --git a/backend/cmd/registration/main.go b/backend/cmd/registration/main.go index 19384fdb..745fb88f 100644 --- a/backend/cmd/registration/main.go +++ b/backend/cmd/registration/main.go @@ -51,7 +51,7 @@ func Main() error { Profiles: profiles.NewClient(balancer.New(sc.InstanceSource(models.Profiles))), } pub := endpoints.NewPublic(a, l) - r, err := register.RegisterEndpoints(deplcfg, l, pub, nil) + r, err := register.Endpoints(deplcfg, l, pub, nil) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) } diff --git a/backend/cmd/registry/main.go b/backend/cmd/registry/main.go index 7aa8c40c..5136f37e 100644 --- a/backend/cmd/registry/main.go +++ b/backend/cmd/registry/main.go @@ -21,7 +21,7 @@ func Main() error { defer a.Stop() e := endpoints.New(a, l) - r, err := register.RegisterEndpoints(deplcfg, l, nil, e) + r, err := register.Endpoints(deplcfg, l, nil, e) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) } diff --git a/backend/cmd/sessions/main.go b/backend/cmd/sessions/main.go index 8f932dc7..da6c63ec 100644 --- a/backend/cmd/sessions/main.go +++ b/backend/cmd/sessions/main.go @@ -47,7 +47,7 @@ func Main() error { pub := endpoints.NewPublic(a, l) pri := endpoints.NewPrivate(a, l) - r, err := register.RegisterEndpoints(deplcfg, l, pub, pri) + r, err := register.Endpoints(deplcfg, l, pub, pri) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) } diff --git a/backend/cmd/tags/main.go b/backend/cmd/tags/main.go index e98b3310..226ce8bd 100644 --- a/backend/cmd/tags/main.go +++ b/backend/cmd/tags/main.go @@ -50,7 +50,7 @@ func Main() error { a := app.New(pool, internalsd) e := endpoints.New(a, sessions, l) - r, err := register.RegisterEndpoints(deplcfg, l, e, nil) + r, err := register.Endpoints(deplcfg, l, e, nil) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) } diff --git a/backend/cmd/users/main.go b/backend/cmd/users/main.go index 8a46d879..128ffe22 100644 --- a/backend/cmd/users/main.go +++ b/backend/cmd/users/main.go @@ -46,7 +46,7 @@ func Main() error { pri := endpoints.NewPrivate(a, l) - r, err := register.RegisterEndpoints(deplcfg, l, nil, pri) + r, err := register.Endpoints(deplcfg, l, nil, pri) if err != nil { return fmt.Errorf("agent.RegisterEndpoints: %w", err) } diff --git a/backend/internal/web/register/agent.go b/backend/internal/web/register/agent.go index f00afcbd..2185afa6 100644 --- a/backend/internal/web/register/agent.go +++ b/backend/internal/web/register/agent.go @@ -23,7 +23,8 @@ func debug(c *deployment.Config, l *logger.Logger, r *http.ServeMux) { r.Handle("GET /", reception.New(c, l.Sub("not-found"), http.HandlerFunc(http.NotFound))) } -func RegisterEndpoints(c *deployment.Config, l *logger.Logger, public, private Lister) (*http.ServeMux, error) { +// For non-gateway services +func Endpoints(c *deployment.Config, l *logger.Logger, public, private Lister) (*http.ServeMux, error) { r := http.NewServeMux() l = l.Sub("register") @@ -61,7 +62,7 @@ func RegisterEndpoints(c *deployment.Config, l *logger.Logger, public, private L return r, nil } -func RegisterForwarders(c *deployment.Config, l *logger.Logger, fwds map[models.Service]*forwarder.LoadBalancedReverseProxy) (*http.ServeMux, error) { +func Forwarders(c *deployment.Config, l *logger.Logger, fwds map[models.Service]*forwarder.LoadBalancedReverseProxy) (*http.ServeMux, error) { r := http.NewServeMux() l = l.Sub("register") From 7a5765781146bdcc308fdbe4320dc64a84c7641f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ufuktan=20Y=C4=B1ld=C4=B1r=C4=B1m?= <13807261+ufukty@users.noreply.github.com> Date: Fri, 12 Jun 2026 20:23:09 +0300 Subject: [PATCH 7/7] be/cmd/int: fixes ignored error value. --- backend/cmd/internal/main.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/cmd/internal/main.go b/backend/cmd/internal/main.go index 5a5c625d..5511f6b7 100644 --- a/backend/cmd/internal/main.go +++ b/backend/cmd/internal/main.go @@ -28,16 +28,19 @@ func Main() error { models.Registry: forwarder.New(registrysd, deplcfg, l), }) if err != nil { - return fmt.Errorf("agent.RegisterForwarders: %w", err) + return fmt.Errorf("registering forwarders: %w", err) } - router.StartServer(router.ServerParameters{ + err = router.StartServer(router.ServerParameters{ Router: deplcfg.Router, Port: deplcfg.Ports.Internal, ServeMux: r, TlsCrt: args.TlsCertificate, TlsKey: args.TlsKey, }, l) + if err != nil { + return fmt.Errorf("starting server: %w", err) + } return nil }