MCPcopy Create free account
hub / github.com/kataras/iris / defaultResultHandler

Function defaultResultHandler

hero/func_result.go:16–48  ·  view source on GitHub ↗
(ctx *context.Context, v interface{})

Source from the content-addressed store, hash-verified

14type ResultHandler func(ctx *context.Context, v interface{}) error
15
16func 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

Callers

nothing calls this directly

Calls 9

TrimHeaderValueFunction · 0.92
GetContentTypeMethod · 0.80
PreflightMethod · 0.65
DispatchMethod · 0.65
XMLMethod · 0.45
YAMLMethod · 0.45
ProtobufMethod · 0.45
MsgPackMethod · 0.45
JSONMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…