使用处理程序的函数

处理程序的函数应实现 Serve(Context) 函数。处理程序函数是注册路由或中间件最简单的方式,实际上它也是处理程序,实现了Handler接口:

type HandlerFunc func(*Context)

func (h HandlerFunc) Serve(c *Context) {
    h(c)
}

处理程序函数应有自己的签名:

func handlerFunc(ctx *iris.Context)  {
    ctx.Writef("Hello")
}

iris.HandleFunc("GET","/letsgetit",handlerFunc)
//OR
iris.Get("/letsgetit", handlerFunc)
iris.Post("/letspostit", handlerFunc)
iris.Put("/letputit", handlerFunc)
iris.Delete("/letsdeleteit", handlerFunc)

results matching ""

    No results matching ""