Documentation ¶
Index ¶
- type ErrorCode
- func (i ErrorCode) Code() uint
- func (i ErrorCode) Error() string
- func (i ErrorCode) IsLocaleSupport(locale string) bool
- func (i ErrorCode) Lang(ctx context.Context, args ...interface{}) string
- func (i ErrorCode) String() string
- func (i ErrorCode) Trans(locale string, args ...interface{}) string
- func (i ErrorCode) TransErrorDetail() *I18nErrorCodeDetail
- func (i ErrorCode) Wrap(err error, locale string, args ...interface{}) *I18nErrorCodeErrorWrap
- func (i ErrorCode) WrapWithContext(ctx context.Context, err error, args ...interface{}) *I18nErrorCodeErrorWrap
- type I18nErrorCodeDetail
- type I18nErrorCodeErrorDetail
- type I18nErrorCodeErrorWrap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrorCode ¶
type ErrorCode uint
ErrorCode Define a custom shaping type that supports i18n as an error code
Specify the error code of a part of the range as the replacement value content of the formatted output NOTE: The range 10000 to 20000 is used as a formatted output replacement component
Assign error code value range
func (ErrorCode) Error ¶
WARNING: You should use Trans, Lang, Wrap, WrapWithContext method instead
- You should not use this method in an internationalized language environment, as well as method String.
- Because this method always returns the translation value of the default language.
- This method implements the error interface, so that you can return the value as an error,
- If you understand the above mechanism then you can use this method with confidence
func (ErrorCode) IsLocaleSupport ¶
IsLocaleSupport Check if the specified locale is supported
func (ErrorCode) Lang ¶
Lang get target translate text use context.Context
- ctx context with Value use Key from _ErrorCode_ctxKey, which pass by gdev-i18n flag -ctxkey
- args Optional placeholder replacement value, value type of ErrorCode, or type of string
func (ErrorCode) String ¶
WARNING: You should use Trans, Lang, Wrap, WrapWithContext method instead
- You should not use this method in an internationalized language environment, as well as method Error.
- Because this method always returns the translation value of the default language.
- This method implements the fmt.Stringer interface, so that you can output it directly by package fmt,
- If you understand the above mechanism then you can use this method with confidence
func (ErrorCode) Trans ¶
Trans get target translate text use specified language locale identifier
- locale specified language locale identifier, need pass by IsLocaleSupport
- args Optional placeholder replacement value, value type of ErrorCode, or type of string
func (ErrorCode) TransErrorDetail ¶
func (i ErrorCode) TransErrorDetail() *I18nErrorCodeDetail
func (ErrorCode) Wrap ¶
func (i ErrorCode) Wrap(err error, locale string, args ...interface{}) *I18nErrorCodeErrorWrap
Wrap another error with locale set for i18n TYPE Const
- err another error
- locale i18n locale name
- args optional formatting component
func (ErrorCode) WrapWithContext ¶
func (i ErrorCode) WrapWithContext(ctx context.Context, err error, args ...interface{}) *I18nErrorCodeErrorWrap
WrapWithContext wrap another error with context.Context set for i18n TYPE Const
- ctx context with Value use Key from _ErrorCode_ctxKey, which pass by gdev-i18n flag -ctxkey
- err another error
- args optional formatting component
type I18nErrorCodeDetail ¶
type I18nErrorCodeDetail struct { ErrString string // wrap another error ErrCode uint // custom shaping type Val Locale string // i18n locale set }
I18nErrorCodeDetail Define a custom shaping type that supports i18n as a struct error code
type I18nErrorCodeErrorDetail ¶
type I18nErrorCodeErrorDetail struct { ErrString string // wrap another error ErrCode uint // custom shaping type Val Locale string // i18n locale set }
新增
type I18nErrorCodeErrorWrap ¶
type I18nErrorCodeErrorWrap struct {
// contains filtered or unexported fields
}
I18nErrorCodeErrorWrap type i18n error wrapper
WARNING This struct ONLY used to wrap the CONST generated by the gdev-i18n tool, Pass easily obtain internationalized translations through Error, String, Translate WARNING
func (*I18nErrorCodeErrorWrap) Error ¶
func (e *I18nErrorCodeErrorWrap) Error() string
Error struct as error, get typed message wrap with inside error message
- this method will be formatted wrap error if exist.
- Only for development and debugging, or logging full error message
- if you want to get typed message, please use method String or Translate
func (*I18nErrorCodeErrorWrap) Format ¶
func (e *I18nErrorCodeErrorWrap) Format() string
Format alias for method Error
- this method will be formatted wrap error if exist.
- Only for development and debugging, or logging full error message
- if you want to get typed message, please use method String or Translate
func (*I18nErrorCodeErrorWrap) String ¶
func (e *I18nErrorCodeErrorWrap) String() string
String implement fmt.Stringer, get translated string use Translate
func (*I18nErrorCodeErrorWrap) Translate ¶
func (e *I18nErrorCodeErrorWrap) Translate() string
Translate get translated string
func (*I18nErrorCodeErrorWrap) Unwrap ¶
func (e *I18nErrorCodeErrorWrap) Unwrap() error
Unwrap an error. Get the error inside
func (*I18nErrorCodeErrorWrap) Value ¶
func (e *I18nErrorCodeErrorWrap) Value() ErrorCode
Value get original type value