dispatchCommon is being used internally to send commonly used data to the response writer with a smart way.
(ctx *context.Context,
statusCode int, contentType string, content []byte, v interface{}, handler ResultHandler, found bool)
| 334 | // dispatchCommon is being used internally to send |
| 335 | // commonly used data to the response writer with a smart way. |
| 336 | func dispatchCommon(ctx *context.Context, |
| 337 | statusCode int, contentType string, content []byte, v interface{}, handler ResultHandler, found bool) error { |
| 338 | // if we have a false boolean as a return value |
| 339 | // then skip everything and fire a not found, |
| 340 | // we even don't care about the given status code or the object or the content. |
| 341 | if !found { |
| 342 | ctx.NotFound() |
| 343 | return nil |
| 344 | } |
| 345 | |
| 346 | status := statusCode |
| 347 | if status == 0 { |
| 348 | status = 200 |
| 349 | } |
| 350 | |
| 351 | // write the status code, the rest will need that before any write ofc. |
| 352 | ctx.StatusCode(status) |
| 353 | if contentType == "" { |
| 354 | // to respect any ctx.ContentType(...) call |
| 355 | // especially if v is not nil. |
| 356 | if contentType = ctx.GetContentType(); contentType == "" { |
| 357 | // 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, |
| 358 | // see dependency-injection/basic/middleware example) |
| 359 | contentType = context.ContentJSONHeaderValue |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | // write the content type now (internal check for empty value) |
| 364 | ctx.ContentType(contentType) |
| 365 | |
| 366 | if v != nil { |
| 367 | return handler(ctx, v) |
| 368 | } |
| 369 | |
| 370 | // .Write even len(content) == 0 , this should be called in order to call the internal tryWriteHeader, |
| 371 | // it will not cost anything. |
| 372 | _, err := ctx.Write(content) |
| 373 | return err |
| 374 | } |
| 375 | |
| 376 | // Response completes the `methodfunc.Result` interface. |
| 377 | // It's being used as an alternative return value which |
no test coverage detected
searching dependent graphs…