From f34703e3cffbb55174813cae52bf450a17f9e088 Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Wed, 17 Feb 2021 16:57:19 +0200 Subject: [PATCH] minor improvement of the previous commit --- HISTORY.md | 2 +- core/router/api_builder.go | 10 ++++++++-- core/router/party.go | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 51e5d9fa..2c2d3959 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -28,7 +28,7 @@ The codebase for Dependency Injection, Internationalization and localization and ## Fixes and Improvements -- New `PartyConfigure(relativePath string, partyReg PartyConfigurator) Party` helper, registers a children Party like `Party` and `PartyFunc` but instead it accepts a structure value (useful when the api's dependencies amount are too much to pass on a function). +- New `PartyConfigure(relativePath string, partyReg ...PartyConfigurator) Party` helper, registers a children Party like `Party` and `PartyFunc` but instead it accepts a structure value (useful when the api's dependencies amount are too much to pass on a function). - **New feature:** add the ability to set custom error handlers on path type parameters errors (existing or custom ones). Example Code: diff --git a/core/router/api_builder.go b/core/router/api_builder.go index e13ae6d3..7fe45e94 100644 --- a/core/router/api_builder.go +++ b/core/router/api_builder.go @@ -870,8 +870,14 @@ type PartyConfigurator interface { // router.Get("/{id:uuid}", api.getUser) // [...] // } -func (api *APIBuilder) PartyConfigure(relativePath string, partyReg PartyConfigurator) Party { - return api.PartyFunc(relativePath, partyReg.Configure) +func (api *APIBuilder) PartyConfigure(relativePath string, partyReg ...PartyConfigurator) Party { + child := api.Party(relativePath) + for _, p := range partyReg { + if p != nil { + p.Configure(child) + } + } + return child } // Subdomain returns a new party which is responsible to register routes to diff --git a/core/router/party.go b/core/router/party.go index df485c03..bd7cc44e 100644 --- a/core/router/party.go +++ b/core/router/party.go @@ -99,7 +99,7 @@ type Party interface { // router.Get("/{id:uuid}", api.getUser) // [...] // } - PartyConfigure(relativePath string, partyReg PartyConfigurator) Party + PartyConfigure(relativePath string, partyReg ...PartyConfigurator) Party // Subdomain returns a new party which is responsible to register routes to // this specific "subdomain". //