mirror of
https://github.com/kataras/iris.git
synced 2026-01-24 04:15:56 +00:00
New APIContainer.EnableStrictMode(bool) method. Read HISTORY.md
This commit is contained in:
@@ -893,11 +893,21 @@ 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)
|
||||
}
|
||||
type (
|
||||
// PartyConfigurator is an interface which all child parties that are registered
|
||||
// through `PartyConfigure` should implement.
|
||||
PartyConfigurator interface {
|
||||
Configure(parent Party)
|
||||
}
|
||||
|
||||
// StrictlyPartyConfigurator is an optional interface which a `PartyConfigurator`
|
||||
// can implement to make sure that all exported fields having a not-nin, non-zero
|
||||
// value before server starts.
|
||||
// StrictlyPartyConfigurator interface {
|
||||
// Strict() bool
|
||||
// }
|
||||
// Good idea but a `mvc or bind:"required"` is a better one I think.
|
||||
)
|
||||
|
||||
// PartyConfigure like `Party` and `PartyFunc` registers a new children Party
|
||||
// but instead it accepts a struct value which should implement the PartyConfigurator interface.
|
||||
|
||||
@@ -79,6 +79,22 @@ func (api *APIContainer) UseResultHandler(handler func(next hero.ResultHandler)
|
||||
return api
|
||||
}
|
||||
|
||||
// EnableStrictMode sets the container's DisablePayloadAutoBinding and MarkExportedFieldsAsRequired to true.
|
||||
// Meaning that all struct's fields (or function's parameters) should be binded manually (except the path parameters).
|
||||
//
|
||||
// Note that children will clone the same properties.
|
||||
// Call the same method with `false` for children
|
||||
// to enable automatic binding on missing dependencies.
|
||||
//
|
||||
// Strict mode is disabled by default;
|
||||
// structs or path parameters that don't match to registered dependencies
|
||||
// are automatically binded from the request context (body and url path parameters respectfully).
|
||||
func (api *APIContainer) EnableStrictMode(strictMode bool) *APIContainer {
|
||||
api.Container.DisablePayloadAutoBinding = strictMode
|
||||
api.Container.MarkExportedFieldsAsRequired = strictMode
|
||||
return api
|
||||
}
|
||||
|
||||
// convertHandlerFuncs accepts Iris hero handlers and returns a slice of native Iris handlers.
|
||||
func (api *APIContainer) convertHandlerFuncs(relativePath string, handlersFn ...interface{}) context.Handlers {
|
||||
fullpath := api.Self.GetRelPath() + relativePath
|
||||
|
||||
Reference in New Issue
Block a user