update jwt dependency and use the current Party if relative path is empty on PartyConfigure only

This commit is contained in:
Gerasimos (Makis) Maropoulos 2021-03-03 14:39:47 +02:00
parent fa81c596df
commit 89f02c6e87
No known key found for this signature in database
GPG Key ID: A771A828097B36C7
5 changed files with 36 additions and 13 deletions

View File

@ -28,7 +28,7 @@ The codebase for Dependency Injection, Internationalization and localization and
## Fixes and Improvements ## 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: - **New feature:** add the ability to set custom error handlers on path type parameters errors (existing or custom ones). Example Code:

View File

@ -873,14 +873,19 @@ type PartyConfigurator interface {
Configure(parent Party) Configure(parent Party)
} }
// PartyConfigure like `Party` and `PartyFunc` registers a new children Party but instead it accepts a struct value. // PartyConfigure like `Party` and `PartyFunc` registers a new children Party
// It initializes a new children Party and executes the PartyConfigurator's Configure. // but instead it accepts a struct value which should implement the PartyConfigurator interface.
// Useful when the api's dependencies amount are too much to pass on a function.
// //
// 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 // RegisterDependencies or ConfigureContainer.RegisterDependency methods
// and "p" is a pointer to a struct then try to bind the unset/zero exported fields // 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. // 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: // Usage:
// app.PartyConfigure("/users", &api.UsersAPI{UserRepository: ..., ...}) // app.PartyConfigure("/users", &api.UsersAPI{UserRepository: ..., ...})
@ -894,7 +899,14 @@ type PartyConfigurator interface {
// app.RegisterDependency(userRepo, ...) // app.RegisterDependency(userRepo, ...)
// app.PartyConfigure("/users", &api.UsersAPI{}) // app.PartyConfigure("/users", &api.UsersAPI{})
func (api *APIBuilder) PartyConfigure(relativePath string, partyReg ...PartyConfigurator) Party { 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 { for _, p := range partyReg {
if p == nil { if p == nil {
continue continue
@ -908,9 +920,15 @@ func (api *APIBuilder) PartyConfigure(relativePath string, partyReg ...PartyConf
p.Configure(child) p.Configure(child)
} }
return child return child
} }
func (api *APIBuilder) configureParty(partyReg ...PartyConfigurator) Party {
return api
}
// Subdomain returns a new party which is responsible to register routes to // Subdomain returns a new party which is responsible to register routes to
// this specific "subdomain". // this specific "subdomain".
// //

View File

@ -160,14 +160,19 @@ type Party interface {
// //
// Look `Party` for more. // Look `Party` for more.
PartyFunc(relativePath string, partyBuilderFunc func(p Party)) Party 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. // PartyConfigure like `Party` and `PartyFunc` registers a new children Party
// It initializes a new children Party and executes the PartyConfigurator's Configure. // but instead it accepts a struct value which should implement the PartyConfigurator interface.
// Useful when the api's dependencies amount are too much to pass on a function.
// //
// 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 // RegisterDependencies or ConfigureContainer.RegisterDependency methods
// and "p" is a pointer to a struct then try to bind the unset/zero exported fields // 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. // 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: // Usage:
// app.PartyConfigure("/users", &api.UsersAPI{UserRepository: ..., ...}) // app.PartyConfigure("/users", &api.UsersAPI{UserRepository: ..., ...})

2
go.mod
View File

@ -21,7 +21,7 @@ require (
github.com/json-iterator/go v1.1.10 github.com/json-iterator/go v1.1.10
github.com/kataras/blocks v0.0.4 github.com/kataras/blocks v0.0.4
github.com/kataras/golog v0.1.7 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/neffos v0.0.18
github.com/kataras/pio v0.0.10 github.com/kataras/pio v0.0.10
github.com/kataras/sitemap v0.0.5 github.com/kataras/sitemap v0.0.5

4
go.sum generated
View File

@ -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/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 h1:0TY5tHn5L5DlRIikepcaRR/6oInIr9AiWsxzt0vvlBE=
github.com/kataras/golog v0.1.7/go.mod h1:jOSQ+C5fUqsNSwurB/oAHq1IFSb0KI3l6GMa7xB6dZA= 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.2 h1:827BBMK2/PQc1Y209cPKeAChyx1mvfW9I3LE0GJ5V8A=
github.com/kataras/jwt v0.1.0/go.mod h1:4ss3aGJi58q3YGmhLUiOvNJnL7UlTXD7+Wf+skgsTmQ= 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 h1:pIxrjV05Q7u6ViFH8eXoOJ53sMARviKz6Vfu5cd9Pb4=
github.com/kataras/neffos v0.0.18/go.mod h1:PZxHcNLbmOcBN4ypym1jTsmmphaMTkcu7VwfnlEA47o= github.com/kataras/neffos v0.0.18/go.mod h1:PZxHcNLbmOcBN4ypym1jTsmmphaMTkcu7VwfnlEA47o=
github.com/kataras/pio v0.0.10 h1:b0qtPUqOpM2O+bqa5wr2O6dN4cQNwSmFd6HQqgVae0g= github.com/kataras/pio v0.0.10 h1:b0qtPUqOpM2O+bqa5wr2O6dN4cQNwSmFd6HQqgVae0g=