hero.ResultHandler can only handle cases where the return value is a custom struct or dispatcher. After reviewing the code, I found that before ResultHandler processing, it needs to go through dispatchFuncResult processing, and then dispatchCommon decides whether to call handlers. I would like to know why it was designed this way.
In scenarios where Container is used to uniformly handle return values, I hope that the return values of all Handlers are uniformly wrapped and processed, so that a unified return value structure can be obtained. However, the framework has specialized handling for some basic types, which forces me to call ctx.JSON(map[string]interface{} {...}) in some handlers.
The code and expected result I hope to achieve is as follows:
hero.ResultHandler
can only handle cases where the return value is a custom struct ordispatcher
. After reviewing the code, I found that beforeResultHandler
processing, it needs to go throughdispatchFuncResult
processing, and thendispatchCommon
decides whether to call handlers. I would like to know why it was designed this way.In scenarios where
Container
is used to uniformly handle return values, I hope that the return values of allHandlers
are uniformly wrapped and processed, so that a unified return value structure can be obtained. However, the framework has specialized handling for some basic types, which forces me to callctx.JSON(map[string]interface{} {...})
in some handlers.The code and expected result I hope to achieve is as follows:
when the return value is
empty
, the expected result is:when the return value is
string
, the expected result is:when the return value is
custom struct
, the expected result is :and so on...