codes

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: MIT Imports: 3 Imported by: 8

Documentation

Overview

Package codes provides ...

Package codes provides ...

Package codes provides ...

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StatusCode

func StatusCode(grpcCode Code) int

StatusCode codes.Code to http status code

func WithTranslator

func WithTranslator(trans Translator)

WithTranslator specific translator

Types

type Code

type Code uint32

Code error code

const (
	LangZhCN = "zh-cn"
	LangEnUS = "en-us"

	// system embeded codes
	// same: https://github.com/grpc/grpc-go/blob/master/codes/codes.go
	// adjust for custom status
	OK                 Code = 0
	Canceled           Code = 1
	Unknown            Code = 2
	InvalidArgument    Code = 3
	DeadlineExceeded   Code = 4
	NotFound           Code = 5
	AlreadyExist       Code = 6
	PermissionDenied   Code = 7
	ResourceExhausted  Code = 8
	FailedPrecondition Code = 9
	Aborted            Code = 10
	OutOfRange         Code = 11
	Unimplemented      Code = 12
	Internal           Code = 13
	Unavailable        Code = 14
	DataLoss           Code = 15
	Unauthenticated    Code = 16
)

list languages

func GRPCCode

func GRPCCode(httpCode int) Code

GRPCCode http status code to codes.Code

func (Code) StatusCode

func (c Code) StatusCode() int

StatusCode codes.Code to http status code

func (Code) String

func (c Code) String() string

String convert to string

func (Code) Tr

func (c Code) Tr(lang string, args ...interface{}) string

Tr translate code to description

type DefaultTranslator

type DefaultTranslator struct {
	Code2Desc map[string]map[Code]string
}

DefaultTranslator memory translator, implements i18n.go/translator

func (DefaultTranslator) SupportedLang

func (t DefaultTranslator) SupportedLang() []string

SupportedLang supported language

func (DefaultTranslator) Tr

func (t DefaultTranslator) Tr(lang string, code Code,
	args ...interface{}) string

Tr translate lang, should not manual call

type Translator

type Translator interface {
	Tr(lang string, code Code, args ...interface{}) string
	SupportedLang() []string
}

Translator translate code to desc

Directories

Path Synopsis
Package status provides ...
Package status provides ...

Jump to

Keyboard shortcuts

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