| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- package common
- import (
- "git.shuncheng.lu/bigthing/gocommon/pkg/cerror"
- "git.shuncheng.lu/bigthing/gocommon/pkg/internal/util"
- "git.shuncheng.lu/bigthing/gocommon/pkg/net/engines"
- )
- const (
- SuccessCode = util.SuccessCode
- FailCode = util.FailCode
- HttpStatus = util.HttpStatus
- )
- func SuccessJson(c *engines.Context, data interface{}) {
- err := c.JSON(
- HttpStatus,
- util.NewSuccessHttpResponse(data),
- )
- if err != nil {
- util.Errorf("[Http-Response] SuccessJson find err, err: %v", err)
- }
- }
- func FailJson(c *engines.Context, err cerror.Cerror) {
- rerr := c.JSON(
- HttpStatus,
- util.NewFailHttpResponse(err),
- )
- if rerr != nil {
- util.Errorf("[Http-Response] FailJson find err, err: %v", err)
- }
- }
- func FailJsonWithMsg(c *engines.Context, message string) {
- err := c.JSON(
- HttpStatus,
- util.NewFailMessageHttpResponse(message),
- )
- if err != nil {
- util.Errorf("[Http-Response] FailJsonWithMsg find err, err: %v", err)
- }
- }
- /**
- MiddlewareBind 中绑定的数据,key(header)->value(header_data)
- */
- func GetMiddlewareBindHeaderData(c *engines.Context) map[string]string {
- result, _ := c.Value(util.HeaderData).(map[string]string)
- if result == nil {
- return map[string]string{}
- }
- return result
- }
|