(ctx *context.Context, v interface{})
| 14 | type ResultHandler func(ctx *context.Context, v interface{}) error |
| 15 | |
| 16 | func defaultResultHandler(ctx *context.Context, v interface{}) error { |
| 17 | if p, ok := v.(PreflightResult); ok { |
| 18 | if err := p.Preflight(ctx); err != nil { |
| 19 | return err |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | if d, ok := v.(Result); ok { |
| 24 | d.Dispatch(ctx) |
| 25 | return nil |
| 26 | } |
| 27 | |
| 28 | switch context.TrimHeaderValue(ctx.GetContentType()) { |
| 29 | case context.ContentXMLHeaderValue, context.ContentXMLUnreadableHeaderValue: |
| 30 | return ctx.XML(v) |
| 31 | case context.ContentYAMLHeaderValue: |
| 32 | return ctx.YAML(v) |
| 33 | case context.ContentProtobufHeaderValue: |
| 34 | msg, ok := v.(proto.Message) |
| 35 | if !ok { |
| 36 | return context.ErrContentNotSupported |
| 37 | } |
| 38 | |
| 39 | _, err := ctx.Protobuf(msg) |
| 40 | return err |
| 41 | case context.ContentMsgPackHeaderValue, context.ContentMsgPack2HeaderValue: |
| 42 | _, err := ctx.MsgPack(v) |
| 43 | return err |
| 44 | default: |
| 45 | // otherwise default to JSON. |
| 46 | return ctx.JSON(v) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | // Result is a response dispatcher. |
| 51 | // All types that complete this interface |
nothing calls this directly
no test coverage detected
searching dependent graphs…