Handler
处理程序,顾名思义,是处理请求的程序。
下面的子章节中描述的每个处理程序注册方法都返回一个RouteNameFunc类型。
处理程序必须实现 Handler 接口:
type Handler interface {
Serve(*Context)
}
// HandlerFunc implements the Handler, it's like the http.Handler and http.HandlerFunc you used to use.
type HandlerFunc func(*Context)
// convert helpers:
// Converts an http.Handler/HandlerFunc/func(w http.ResponseWriter, r *http.Request) to an iris Handler, this way you can use third-party handlers.
ToHandler(maybeHttpHandler interface{}) iris.HandlerFunc
// Converts an iris Handler to a native http.Handler, this way you can use your iris' handler to integrate with other http servers you may need somewhere.
ToNativeHandler(h iris.Handler) http.Handler
在处理程序注册后,就可以使用它返回的RouteNameFunc 类型(实际上就是一个 func 类型)给处理程序注册名称,以便在代码或模板中更容易地查找到。有关更多信息,请检查路由和反向查找部分。