1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-23 11:56:00 +00:00

add a dependency-injection examples folder for the next release and some improvements

Former-commit-id: 040168afb7caf808618f7da5e68ae8eb01cb7170
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-03-01 02:17:19 +02:00
parent 5fc24812bc
commit ce2eae9121
19 changed files with 214 additions and 76 deletions

View File

@@ -225,7 +225,7 @@ func dispatchFuncResult(ctx context.Context, values []reflect.Value) error {
continue
}
if statusCode < 400 {
if statusCode < 400 && value != ErrStopExecution {
statusCode = DefaultErrStatusCode
}
@@ -286,7 +286,11 @@ func dispatchCommon(ctx context.Context,
if contentType == "" {
// to respect any ctx.ContentType(...) call
// especially if v is not nil.
contentType = ctx.GetContentType()
if contentType = ctx.GetContentType(); contentType == "" {
// if it's still empty set to JSON. (useful for dynamic middlewares that returns an int status code and the next handler dispatches the JSON,
// see dependency-injection/basic/middleware example)
contentType = context.ContentJSONHeaderValue
}
}
if v != nil {
@@ -302,10 +306,13 @@ func dispatchCommon(ctx context.Context,
if strings.HasPrefix(contentType, context.ContentJavascriptHeaderValue) {
_, err = ctx.JSONP(v)
} else if strings.HasPrefix(contentType, context.ContentXMLHeaderValue) {
_, err = ctx.XML(v, context.XML{Indent: " "})
_, err = ctx.XML(v)
// no need: context.XML{Indent: " "}), after v12.2,
// if not iris.WithOptimizations passed and indent is empty then it sets it to two spaces for JSON, JSONP and XML,
// otherwise given indentation.
} else {
// defaults to json if content type is missing or its application/json.
_, err = ctx.JSON(v, context.JSON{Indent: " "})
_, err = ctx.JSON(v)
}
return err