1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-22 04:17:03 +00:00

dependency injection: func (...<T>) iris.Handler can be generated to a simple iris handler if <T> are static dependencies

This commit is contained in:
Gerasimos (Makis) Maropoulos
2021-06-10 21:16:00 +03:00
parent 8f9140b705
commit 96c2dec47f
6 changed files with 58 additions and 7 deletions

View File

@@ -315,6 +315,26 @@ func Handler(fn interface{}) context.Handler {
// custom structs, Result(View | Response) and more.
// It returns a standard `iris/context.Handler` which can be used anywhere in an Iris Application,
// as middleware or as simple route handler or subdomain's handler.
//
// func(...<T>) iris.Handler
// - if <T> are all static dependencies then
// there is no reflection involved at serve-time.
//
// func(pathParameter string, ...<T>)
// - one or more path parameters (e.g. :uid, :string, :int, :path, :uint64)
// are automatically binded to the first input Go standard types (string, int, uint64 and e.t.c.)
//
// func(<T>) error
// - if a function returns an error then this error's text is sent to the client automatically.
//
// func(<T>) <R>
// - The result of the function is a dependency too.
// If <R> is a request-scope dependency (dynamic) then
// this function will be called at every request.
//
// func(<T>) <R>
// - If <R> is static dependency (e.g. a database or a service) then its result
// can be used as a static dependency to the next dependencies or to the controller/function itself.
func (c *Container) Handler(fn interface{}) context.Handler {
return c.HandlerWithParams(fn, 0)
}