mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 10:41:03 +01:00
Add new PartyConfigure helper
This commit is contained in:
parent
5ccd80a6cd
commit
cbf70a7bcf
|
@ -28,6 +28,8 @@ 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 (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:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
|
|
|
@ -852,6 +852,28 @@ func (api *APIBuilder) PartyFunc(relativePath string, partyBuilderFunc func(p Pa
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PartyConfigurator is an interface which all child parties that are registered
|
||||||
|
// through `PartyConfigure` should implement.
|
||||||
|
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.
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
// app.PartyConfigure("/users", &api.UsersAPI{UserRepository: ..., ...})
|
||||||
|
// Where UsersAPI looks like:
|
||||||
|
// type UsersAPI struct { [...] }
|
||||||
|
// func(api *UsersAPI) Configure(router iris.Party) {
|
||||||
|
// router.Get("/{id:uuid}", api.getUser)
|
||||||
|
// [...]
|
||||||
|
// }
|
||||||
|
func (api *APIBuilder) PartyConfigure(relativePath string, partyReg PartyConfigurator) Party {
|
||||||
|
return api.PartyFunc(relativePath, partyReg.Configure)
|
||||||
|
}
|
||||||
|
|
||||||
// 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".
|
||||||
//
|
//
|
||||||
|
|
|
@ -87,6 +87,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.
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Usage:
|
||||||
|
// app.PartyConfigure("/users", &api.UsersAPI{UserRepository: ..., ...})
|
||||||
|
// Where UsersAPI looks like:
|
||||||
|
// type UsersAPI struct { [...] }
|
||||||
|
// func(api *UsersAPI) Configure(router iris.Party) {
|
||||||
|
// router.Get("/{id:uuid}", api.getUser)
|
||||||
|
// [...]
|
||||||
|
// }
|
||||||
|
PartyConfigure(relativePath string, partyReg PartyConfigurator) Party
|
||||||
// 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".
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in New Issue
Block a user