mirror of
https://github.com/kataras/iris.git
synced 2025-12-17 18:07:01 +00:00
Add new PartyConfigure helper
This commit is contained in:
@@ -852,6 +852,28 @@ func (api *APIBuilder) PartyFunc(relativePath string, partyBuilderFunc func(p Pa
|
||||
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
|
||||
// this specific "subdomain".
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user