Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何将响应结果的 msg 改为 message? #49

Open
GanZhiXiong opened this issue Jan 6, 2023 · 3 comments
Open

如何将响应结果的 msg 改为 message? #49

GanZhiXiong opened this issue Jan 6, 2023 · 3 comments

Comments

@GanZhiXiong
Copy link

GanZhiXiong commented Jan 6, 2023

我知道在 gtoken_resp.go 文件中可以直接修改,有没有不修改库本身文件的方法?

type Resp struct {
	Code int         `json:"code"`
	Msg  string      `json:"message"`
	Data interface{} `json:"data"`
}
@GanZhiXiong
Copy link
Author

查了一下,实现 LoginAfterFunc 方法,可以重写 response,来实现将 msg 改为 message:

func LoginAfterFunc(r *ghttp.Request, respData gtoken.Resp) {
	r.Response.WriteJson(g.Map{
		"code":    respData.Code,
		"message": respData.Msg,
		"data":    respData.Data,
	})
}

@GanZhiXiong
Copy link
Author

@zcool321

但是如果未认证,的 response 如何重新呢?尝试了 AuthAfterFunc,它会使实际响应不执行,直接返回 AuthAfterFunc 的 response:

func AuthAfterFunc(r *ghttp.Request, respData gtoken.Resp) {
	r.Response.WriteJson(g.Map{
		"code":     respData.Code,
		"message": respData.Msg,
		"data":     respData.Data,
	})
}
{
    "code": 0,
    "data": {
        "createTime": 1673083704166,
        "data": "1",
        "refreshTime": 1673515704166,
        "userKey": "test",
        "uuid": "feca4c8130990b85bc2ba63944e666fc"
    },
    "message": "success"
}

有没有通过更简单的配置来重新定义 response,比如将 msg 改为 message,有实现此功能吗?

@alaywn
Copy link

alaywn commented Apr 3, 2023

这个库更新太慢了,也不理会issue或pr,建议fork后自己改,或者自己写个

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants