mirror of
https://github.com/kataras/iris.git
synced 2026-01-10 21:45:57 +00:00
replace ioutil with io package and other minor improvements
This commit is contained in:
@@ -326,23 +326,28 @@ func Handler(fn interface{}) context.Handler {
|
||||
// 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
|
||||
// func(...<T>) iris.Handler
|
||||
//
|
||||
// - if <T> are all static dependencies then
|
||||
// there is no reflection involved at serve-time.
|
||||
//
|
||||
// func(pathParameter string, ...<T>)
|
||||
// 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
|
||||
// func(<T>) error
|
||||
//
|
||||
// - if a function returns an error then this error's text is sent to the client automatically.
|
||||
//
|
||||
// func(<T>) <R>
|
||||
// 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>
|
||||
// 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 {
|
||||
|
||||
@@ -27,11 +27,9 @@ func defaultResultHandler(ctx *context.Context, v interface{}) error {
|
||||
|
||||
switch context.TrimHeaderValue(ctx.GetContentType()) {
|
||||
case context.ContentXMLHeaderValue, context.ContentXMLUnreadableHeaderValue:
|
||||
_, err := ctx.XML(v)
|
||||
return err
|
||||
return ctx.XML(v)
|
||||
case context.ContentYAMLHeaderValue:
|
||||
_, err := ctx.YAML(v)
|
||||
return err
|
||||
return ctx.YAML(v)
|
||||
case context.ContentProtobufHeaderValue:
|
||||
msg, ok := v.(proto.Message)
|
||||
if !ok {
|
||||
@@ -45,8 +43,7 @@ func defaultResultHandler(ctx *context.Context, v interface{}) error {
|
||||
return err
|
||||
default:
|
||||
// otherwise default to JSON.
|
||||
_, err := ctx.JSON(v)
|
||||
return err
|
||||
return ctx.JSON(v)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ func (e err) Dispatch(ctx iris.Context) {
|
||||
// write the status code based on the err's StatusCode.
|
||||
ctx.StatusCode(e.Status)
|
||||
// send to the client the whole object as json
|
||||
_, _ = ctx.JSON(e)
|
||||
_ = ctx.JSON(e)
|
||||
}
|
||||
|
||||
func GetCustomErrorAsDispatcher() err {
|
||||
|
||||
Reference in New Issue
Block a user