diff --git a/HISTORY.md b/HISTORY.md index 6285a1e3..811f6a48 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 which may contain one or more of the dependencies registered by `RegisterDependency` or `ConfigureContainer().RegisterDependency` methods and fills the unset/zero exported struct's fields respectfully (useful when the api's dependencies amount are too much to pass on a function). +- New `Party.PartyConfigure(relativePath string, partyReg ...PartyConfigurator) Party` helper, registers a children Party like `Party` and `PartyFunc` but instead it accepts a structure value which may contain one or more of the dependencies registered by `RegisterDependency` or `ConfigureContainer().RegisterDependency` methods and fills the unset/zero exported struct's fields respectfully (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 37f18c80..d1f32dd6 100644 --- a/core/router/api_builder.go +++ b/core/router/api_builder.go @@ -873,14 +873,19 @@ type PartyConfigurator interface { Configure(parent Party) } -// PartyConfigure like `Party` and `PartyFunc` registers a new children Party but instead it accepts a struct value. -// It initializes a new children Party and executes the PartyConfigurator's Configure. -// Useful when the api's dependencies amount are too much to pass on a function. +// PartyConfigure like `Party` and `PartyFunc` registers a new children Party +// but instead it accepts a struct value which should implement the PartyConfigurator interface. // -// As an exception, if the end-developer registered one or more dependencies upfront through +// PartyConfigure accepts the relative path of the child party +// (As an exception, if it's empty then all configurators are applied to the current Party) +// and one or more Party configurators and +// executes the PartyConfigurator's Configure method. +// +// If the end-developer registered one or more dependencies upfront through // RegisterDependencies or ConfigureContainer.RegisterDependency methods // and "p" is a pointer to a struct then try to bind the unset/zero exported fields // to the registered dependencies, just like we do with Controllers. +// Useful when the api's dependencies amount are too much to pass on a function. // // Usage: // app.PartyConfigure("/users", &api.UsersAPI{UserRepository: ..., ...}) @@ -894,7 +899,14 @@ type PartyConfigurator interface { // app.RegisterDependency(userRepo, ...) // app.PartyConfigure("/users", &api.UsersAPI{}) func (api *APIBuilder) PartyConfigure(relativePath string, partyReg ...PartyConfigurator) Party { - child := api.Party(relativePath) + var child Party + + if relativePath == "" { + child = api + } else { + child = api.Party(relativePath) + } + for _, p := range partyReg { if p == nil { continue @@ -908,9 +920,15 @@ func (api *APIBuilder) PartyConfigure(relativePath string, partyReg ...PartyConf p.Configure(child) } + return child } +func (api *APIBuilder) configureParty(partyReg ...PartyConfigurator) Party { + + return api +} + // Subdomain returns a new party which is responsible to register routes to // this specific "subdomain". // diff --git a/core/router/party.go b/core/router/party.go index 7b01c493..d3d5ebf5 100644 --- a/core/router/party.go +++ b/core/router/party.go @@ -160,14 +160,19 @@ type Party interface { // // Look `Party` for more. PartyFunc(relativePath string, partyBuilderFunc func(p Party)) Party - // PartyConfigure like `Party` and `PartyFunc` registers a new children Party but instead it accepts a struct value. - // It initializes a new children Party and executes the PartyConfigurator's Configure. - // Useful when the api's dependencies amount are too much to pass on a function. + // PartyConfigure like `Party` and `PartyFunc` registers a new children Party + // but instead it accepts a struct value which should implement the PartyConfigurator interface. // - // As an exception, if the end-developer registered one or more dependencies upfront through + // PartyConfigure accepts the relative path of the child party + // (As an exception, if it's empty then all configurators are applied to the current Party) + // and one or more Party configurators and + // executes the PartyConfigurator's Configure method. + // + // If the end-developer registered one or more dependencies upfront through // RegisterDependencies or ConfigureContainer.RegisterDependency methods // and "p" is a pointer to a struct then try to bind the unset/zero exported fields // to the registered dependencies, just like we do with Controllers. + // Useful when the api's dependencies amount are too much to pass on a function. // // Usage: // app.PartyConfigure("/users", &api.UsersAPI{UserRepository: ..., ...}) diff --git a/go.mod b/go.mod index bcd6ed4e..9e5edf65 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/json-iterator/go v1.1.10 github.com/kataras/blocks v0.0.4 github.com/kataras/golog v0.1.7 - github.com/kataras/jwt v0.1.0 + github.com/kataras/jwt v0.1.2 github.com/kataras/neffos v0.0.18 github.com/kataras/pio v0.0.10 github.com/kataras/sitemap v0.0.5 diff --git a/go.sum b/go.sum index e5fc141f..a0843674 100644 --- a/go.sum +++ b/go.sum @@ -136,8 +136,8 @@ github.com/kataras/blocks v0.0.4 h1:lvp/Yr7WoYJKuHpI8f4Shlsl1lb+PE2Lyt0qta5kYWA= github.com/kataras/blocks v0.0.4/go.mod h1:fu8wIPm3TgpiqW1fdPUSR8m/VMcZgj52vBYe1aS1mu0= github.com/kataras/golog v0.1.7 h1:0TY5tHn5L5DlRIikepcaRR/6oInIr9AiWsxzt0vvlBE= github.com/kataras/golog v0.1.7/go.mod h1:jOSQ+C5fUqsNSwurB/oAHq1IFSb0KI3l6GMa7xB6dZA= -github.com/kataras/jwt v0.1.0 h1:sObn9JBWgl8eStRdQfetL5AxdNvx1VuT1qTuv/20MW4= -github.com/kataras/jwt v0.1.0/go.mod h1:4ss3aGJi58q3YGmhLUiOvNJnL7UlTXD7+Wf+skgsTmQ= +github.com/kataras/jwt v0.1.2 h1:827BBMK2/PQc1Y209cPKeAChyx1mvfW9I3LE0GJ5V8A= +github.com/kataras/jwt v0.1.2/go.mod h1:4ss3aGJi58q3YGmhLUiOvNJnL7UlTXD7+Wf+skgsTmQ= github.com/kataras/neffos v0.0.18 h1:pIxrjV05Q7u6ViFH8eXoOJ53sMARviKz6Vfu5cd9Pb4= github.com/kataras/neffos v0.0.18/go.mod h1:PZxHcNLbmOcBN4ypym1jTsmmphaMTkcu7VwfnlEA47o= github.com/kataras/pio v0.0.10 h1:b0qtPUqOpM2O+bqa5wr2O6dN4cQNwSmFd6HQqgVae0g=