本文整理汇总了Golang中github.com/app-kit/go-appkit.Response.SetMeta方法的典型用法代码示例。如果您正苦于以下问题:Golang Response.SetMeta方法的具体用法?Golang Response.SetMeta怎么用?Golang Response.SetMeta使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/app-kit/go-appkit.Response
的用法示例。
在下文中一共展示了Response.SetMeta方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SerializeResponseMiddleware
func SerializeResponseMiddleware(registry kit.Registry, request kit.Request, response kit.Response) (kit.Response, bool) {
// Try to serialize the reponse data.
// Determine serializer.
serializer := registry.DefaultSerializer()
// Check if a custom serializer was specified.
if name := request.GetContext().String("response-serializer"); name != "" {
serializer = registry.Serializer(name)
if serializer == nil {
errResp := kit.NewErrorResponse("unknown_response_serializer", true)
data, _ := serializer.MustSerializeResponse(errResp)
errResp.SetData(data)
return errResp, false
}
}
// Set format in metadata.
meta := response.GetMeta()
if meta == nil {
meta = make(map[string]interface{})
}
meta["format"] = serializer.Name()
response.SetMeta(meta)
data, err := serializer.MustSerializeResponse(response)
if err != nil {
registry.Logger().Errorf("Response serialization error: %v (%+v)", err, response)
}
response.SetData(data)
return nil, false
}