gen-proto-error

command
v0.0.29 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

gen-proto-error

Generate *berror.Error errors from proto
从proto生成 *berror.Error的错误

References

github.com/ravinggo/game/proto/error.proto
google/protobuf/descriptor.proto

gen-proto-error parses all enumeration types ending with ErrorCode and enumeration fields must add basepb.error_info annotation
gen-proto-error 解析所有以 ErrorCode 结尾的枚举类型 并且枚举字段必须添加 basepb.error_info 注解

enum XXXErrorCode {
    XXXErrorItemNotEnough = 0[(basepb.error_info) = {tip_desc:"道具不足"}];
}

Usage

 gen-proto-error --parseDir={dira},{dirb},{dirc} --txtPath={txtPath} --goPath={goPath} --pkgName={pkgName}
 
parseDir:
  The proto directory that needs to be parsed to generate ErrMsg. Multiple directories are separated by commas.
  需要解析生成 ErrMsg 的 proto 目录,多个目录用逗号分隔

txtPath:
  The path of the generated ErrMsg text file, used by the client in multiple languages
  生成的 ErrMsg 文本文件路径,客户端多语言使用
  
goPath:
  The path of the generated ErrMsg code file
  生成的 ErrMsg 代码文件路径 

pkgName:
  The package name of the generated ErrMsg code file
  生成的 ErrMsg 代码文件包名

examples

https://github.com/ravinggo/examples/proto

// login.proto in the login directory
syntax = "proto3";

package login;
option go_package = "pbmsg/login";

// copy from github.com/ravinggo/game/proto/error.proto
import "error.proto";

enum LoginErrorCode {
  LoginErrorInvalidLoginType = 0 [(basepb.error_info) = {tip_desc:"无效的登录类型"}];
  LoginErrorTokenExpired = 1 [(basepb.error_info) = {tip_desc:"token已过期"}];
  LoginErrorAccountIsNotRegistered = 2 [(basepb.error_info) = {tip_desc:"账号未注册"}];
  LoginErrorAccountIsRegistered = 3 [(basepb.error_info) = {tip_desc:"账号已注册请登录"}];
  LoginErrorFormatError = 4 [(basepb.error_info) = {tip_desc:"账号格式不符合要求"}];
  LoginErrorPasswordFormatError = 5 [(basepb.error_info) = {tip_desc:"密码格式不符合要求"}];
  LoginErrorNotRealNameAuthentication = 6 [(basepb.error_info) = {tip_desc:"账号未实名认证"}];
  LoginErrorAccountIsWrong = 7 [(basepb.error_info) = {tip_desc:"账号密码错误"}];
  LoginErrorAuthenticationNotApproved = 8 [(basepb.error_info) = {tip_desc:"账号认证不通过"}];
  LoginErrorAgeLimit = 9 [(basepb.error_info) = {tip_desc:"年龄限制"}];
  LoginErrorLimitPlayTimeConfigWrong = 10 [(basepb.error_info) = {tip_desc:"未成年游玩时间配置错误"}];
  LoginErrorFeedbackContentTooLong = 11 [(basepb.error_info) = {tip_desc:"反馈内容长度需在200字符以内"}];
  LoginErrorFeedbackContactTooLong = 12 [(basepb.error_info) = {tip_desc:"联系方式长度需在30字符以内"}];
  LoginErrorTokenExpiredIsReconnect = 13 [(basepb.error_info) = {tip_desc:"token已过期"}];
}

then run

gen-proto-error --parseDir=./login --txtPath=. --goPath={your project dir}/errmsg --pkgName={errmsg}

error_code.txt

login_error_account_is_not_registered=账号未注册
login_error_account_is_registered=账号已注册请登录
login_error_account_is_wrong=账号密码错误
login_error_age_limit=年龄限制
login_error_authentication_not_approved=账号认证不通过
login_error_feedback_contact_too_long=联系方式长度需在30字符以内
login_error_feedback_content_too_long=反馈内容长度需在200字符以内
login_error_format_error=账号格式不符合要求
login_error_invalid_login_type=无效的登录类型
login_error_limit_play_time_config_wrong=未成年游玩时间配置错误
login_error_not_real_name_authentication=账号未实名认证
login_error_password_format_error=密码格式不符合要求
login_error_token_expired=token已过期
login_error_token_expired_is_reconnect=token已过期

errmsg/error_code.go

// Code generated by gen-proto-error. DO NOT EDIT.
// source: ./login
package errmsg

import (
	berror "github.com/ravinggo/game/common/berror"
)


func NewLoginErrorAccountIsNotRegistered(extra ...string) *berror.ErrMsg {
	e := berror.GetErr()
	e.ErrCode = 1
	e.ErrMsg = "login_error_account_is_not_registered"
	if berror.IsOpenStack() {
		e.WithStackTrace()
	}
	if len(extra) > 0 {
		e.ErrExtraInfo = extra[0]
	}
	return e
}

func NewLoginErrorAccountIsRegistered(extra ...string) *berror.ErrMsg {
	e := berror.GetErr()
	e.ErrCode = 1
	e.ErrMsg = "login_error_account_is_registered"
	if berror.IsOpenStack() {
		e.WithStackTrace()
	}
	if len(extra) > 0 {
		e.ErrExtraInfo = extra[0]
	}
	return e
}

func NewLoginErrorAccountIsWrong(extra ...string) *berror.ErrMsg {
	e := berror.GetErr()
	e.ErrCode = 1
	e.ErrMsg = "login_error_account_is_wrong"
	if berror.IsOpenStack() {
		e.WithStackTrace()
	}
	if len(extra) > 0 {
		e.ErrExtraInfo = extra[0]
	}
	return e
}

func NewLoginErrorAgeLimit(extra ...string) *berror.ErrMsg {
	e := berror.GetErr()
	e.ErrCode = 1
	e.ErrMsg = "login_error_age_limit"
	if berror.IsOpenStack() {
		e.WithStackTrace()
	}
	if len(extra) > 0 {
		e.ErrExtraInfo = extra[0]
	}
	return e
}

func NewLoginErrorAuthenticationNotApproved(extra ...string) *berror.ErrMsg {
	e := berror.GetErr()
	e.ErrCode = 1
	e.ErrMsg = "login_error_authentication_not_approved"
	if berror.IsOpenStack() {
		e.WithStackTrace()
	}
	if len(extra) > 0 {
		e.ErrExtraInfo = extra[0]
	}
	return e
}

func NewLoginErrorFeedbackContactTooLong(extra ...string) *berror.ErrMsg {
	e := berror.GetErr()
	e.ErrCode = 1
	e.ErrMsg = "login_error_feedback_contact_too_long"
	if berror.IsOpenStack() {
		e.WithStackTrace()
	}
	if len(extra) > 0 {
		e.ErrExtraInfo = extra[0]
	}
	return e
}

func NewLoginErrorFeedbackContentTooLong(extra ...string) *berror.ErrMsg {
	e := berror.GetErr()
	e.ErrCode = 1
	e.ErrMsg = "login_error_feedback_content_too_long"
	if berror.IsOpenStack() {
		e.WithStackTrace()
	}
	if len(extra) > 0 {
		e.ErrExtraInfo = extra[0]
	}
	return e
}

func NewLoginErrorFormatError(extra ...string) *berror.ErrMsg {
	e := berror.GetErr()
	e.ErrCode = 1
	e.ErrMsg = "login_error_format_error"
	if berror.IsOpenStack() {
		e.WithStackTrace()
	}
	if len(extra) > 0 {
		e.ErrExtraInfo = extra[0]
	}
	return e
}

func NewLoginErrorInvalidLoginType(extra ...string) *berror.ErrMsg {
	e := berror.GetErr()
	e.ErrCode = 1
	e.ErrMsg = "login_error_invalid_login_type"
	if berror.IsOpenStack() {
		e.WithStackTrace()
	}
	if len(extra) > 0 {
		e.ErrExtraInfo = extra[0]
	}
	return e
}

func NewLoginErrorLimitPlayTimeConfigWrong(extra ...string) *berror.ErrMsg {
	e := berror.GetErr()
	e.ErrCode = 1
	e.ErrMsg = "login_error_limit_play_time_config_wrong"
	if berror.IsOpenStack() {
		e.WithStackTrace()
	}
	if len(extra) > 0 {
		e.ErrExtraInfo = extra[0]
	}
	return e
}

func NewLoginErrorNotRealNameAuthentication(extra ...string) *berror.ErrMsg {
	e := berror.GetErr()
	e.ErrCode = 1
	e.ErrMsg = "login_error_not_real_name_authentication"
	if berror.IsOpenStack() {
		e.WithStackTrace()
	}
	if len(extra) > 0 {
		e.ErrExtraInfo = extra[0]
	}
	return e
}

func NewLoginErrorPasswordFormatError(extra ...string) *berror.ErrMsg {
	e := berror.GetErr()
	e.ErrCode = 1
	e.ErrMsg = "login_error_password_format_error"
	if berror.IsOpenStack() {
		e.WithStackTrace()
	}
	if len(extra) > 0 {
		e.ErrExtraInfo = extra[0]
	}
	return e
}

func NewLoginErrorTokenExpired(extra ...string) *berror.ErrMsg {
	e := berror.GetErr()
	e.ErrCode = 1
	e.ErrMsg = "login_error_token_expired"
	if berror.IsOpenStack() {
		e.WithStackTrace()
	}
	if len(extra) > 0 {
		e.ErrExtraInfo = extra[0]
	}
	return e
}

func NewLoginErrorTokenExpiredIsReconnect(extra ...string) *berror.ErrMsg {
	e := berror.GetErr()
	e.ErrCode = 1
	e.ErrMsg = "login_error_token_expired_is_reconnect"
	if berror.IsOpenStack() {
		e.WithStackTrace()
	}
	if len(extra) > 0 {
		e.ErrExtraInfo = extra[0]
	}
	return e
}



Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL