lang

package
v0.0.0-...-5c85043 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

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

const (
	ComUserName ErrorCode = 10000 + iota
	ComUserPwd
)

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

const (
	Ok ErrorCode = 20000 + iota
	UserLoginInvalid
	MerchantLoginInvalid
	SubDirectoryTest
)

Assign error code value range

func (ErrorCode) Code

func (i ErrorCode) Code() uint

Code get original type uint value

func (ErrorCode) Error

func (i ErrorCode) Error() 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 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

func (i ErrorCode) IsLocaleSupport(locale string) bool

IsLocaleSupport Check if the specified locale is supported

func (ErrorCode) Lang

func (i ErrorCode) Lang(ctx context.Context, args ...interface{}) string

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

func (i ErrorCode) String() 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

func (i ErrorCode) Trans(locale string, args ...interface{}) string

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

Jump to

Keyboard shortcuts

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