handler-func

command
v14.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

HandlerFunc: dependency injection for plain handlers and middleware.

Controllers are not the only consumers of the container. app.HandlerFunc takes a function whose parameters are registered dependencies and which returns an iris.Handler. The outer function runs once, at startup, with the arguments injected; the handler it returns serves the requests. app.HandlerFuncs maps a whole list at once, and the builder's Middlewares/RouterMiddlewares steps accept the same shape mixed with plain handlers.

It panics at startup on an unresolvable parameter, a nil result or a result that is not a handler - the graph is verified before the port is bound.

Learn: inject registered dependencies into plain handlers and middleware with app.HandlerFunc and app.HandlerFuncs. Before: ../constructors

Run:

go run main.go

Try:

curl http://localhost:8080/                        # 200, {"message":"hello"}
curl http://localhost:8080/stats                   # 200, hit counts per path
curl http://localhost:8080/healthz                 # 200, ok
curl -i http://localhost:8080/admin                # 403 PERMISSION_DENIED without the header
curl -H 'X-Admin: 1' http://localhost:8080/admin   # 200, {"area":"admin"}

Next: ../request-scoped

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL