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

why response use enum's name #970

Closed
t2krew opened this issue Jul 10, 2019 · 4 comments
Closed

why response use enum's name #970

t2krew opened this issue Jul 10, 2019 · 4 comments

Comments

@t2krew
Copy link

t2krew commented Jul 10, 2019

I have rewrote code with grpc-gateway, but got the different response.
this is the response what i want:

{
"code": -100,
"info": "缺少参数userid",
"RecordLists": []
}

but now i got :

{
"code": "PARAMERR",
"info": "缺少参数userid",
"RecordLists": []
}

the code in response I use the enum.

and this is my .proto's enum

// 返回码
enum CODE {
	UNKNOWN = 0;
	OK = 1; // 成功
	REJECT = -1; //
	MISSBIZNO = -10;  // 缺少参数bizno
	MISSBIZTYPE = -11; // 缺少参数biztype
	MISSUSERID = -12; // 缺少参数userid
	MISSNUM = -13; // 缺少参数num
	MISSSIGN = -14; // 缺少参数sign
	INVALIDBIZNO = -20; // 无效的bizno
	UNUSUALBIZNO = -22; // bizno信息异常
	INVALIDBIZTYPE = -21; // 无效的biztype
	UNUSUALBIZTYPE = -23; // biztype信息异常
	INVALIDSIGN = -30; // 签名错误
	INVALIDUSER = -40; // 非会员用户

	PARAMERR = -100; // 参数错误
	UNLOGIN = -101;  // 未登录

	INTERNALERR = -999; // 内部错误
}

how to solve this ?

@t2krew t2krew changed the title why response use enum name why response use enum's name Jul 10, 2019
@johanbrandhorst
Copy link
Collaborator

You can configure your JSON marshaller to output enums as ints.

m := runtime.JSONPb{
    EnumsAsInts: true,
}
mux := runtime.NewServeMux(runtime.WithMarshalerOption("*", &m))

@t2krew
Copy link
Author

t2krew commented Jul 10, 2019

@johanbrandhorst it works, thank you so much! :-)

@johanbrandhorst
Copy link
Collaborator

@t2krew I'm glad it worked for you, but in the future please read the issue template and reach out to us on gophers slack (#grpc-gateway) instead of opening issues. This would've saved us both a lot of time.

@t2krew
Copy link
Author

t2krew commented Jul 10, 2019

@johanbrandhorst ok, i will. Thanks again

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