base

package module
v0.0.0-...-c1449ee Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 License: MIT Imports: 8 Imported by: 0

README

go-base

common libraries for go

Documentation

Index

Constants

View Source
const (
	Black _TextColor = iota + 30
	Red
	Green
	Yellow
	Blue
	Magenta
	Cyan
	White
)

Foreground colors.

Variables

View Source
var (
	SUCCESS = &result{0, "", nil}
	UNKNOWN = &result{-1, "未知错误", nil}

	START = &result{-2000, "start of error", nil}
	END   = &result{-3000, "end of error", nil}

	INVALID_PARAM       = &result{START.ICode - 1, "无效的参数", nil}      // invalid param
	TARGET_NOT_FOUND    = &result{START.ICode - 2, "目标不存在", nil}      // target not found
	ACTION_ILLEGAL      = &result{START.ICode - 3, "操作非法", nil}       // action illegal
	ACTION_TIMEOUT      = &result{START.ICode - 4, "操作超时", nil}       // action timeout
	ACTION_CANCELED     = &result{START.ICode - 5, "操作被取消", nil}      // action canceled
	ACTION_UNSUPPORTED  = &result{START.ICode - 6, "不支持的操作", nil}     // action unsupported
	LOGICAL_ERROR       = &result{START.ICode - 7, "逻辑错误", nil}       // logical error
	INTERNAL_ERROR      = &result{START.ICode - 10, "内部错误", nil}      // internal error
	REMOTE_SYSTEM_ERROR = &result{START.ICode - 11, "远端系统错误", nil}    // remote system error
	TRY_AGAIN_LATER     = &result{START.ICode - 12, "操作失败,稍后再试", nil} // action failed, try again later
)
View Source
var (
	ErrorChannelIsFull = errors.New("channel is full")
)
View Source
var (
	RecommendedEncoderConfig = zapcore.EncoderConfig{
		CallerKey:        "caller",
		LevelKey:         "level",
		MessageKey:       "msg",
		TimeKey:          "ts",
		StacktraceKey:    "stacktrace",
		LineEnding:       zapcore.DefaultLineEnding,
		EncodeTime:       customTimeEncoder,
		EncodeLevel:      customLevelEncoder,
		EncodeCaller:     customCallerEncoder,
		EncodeDuration:   zapcore.SecondsDurationEncoder,
		EncodeName:       zapcore.FullNameEncoder,
		ConsoleSeparator: " ",
	}
)

Functions

func InitDefaultLogger

func InitDefaultLogger()

func InitLogger

func InitLogger(name string, cfg *logger.Config)

func InitSimpleLogger

func InitSimpleLogger(name, level string)

Types

type Callback

type Callback func(result Result)

func (Callback) On

func (c Callback) On(result Result)

func (Callback) OnSuccess

func (c Callback) OnSuccess()

func (Callback) OnSuccessD

func (c Callback) OnSuccessD(data any)

type RecyclableChan

type RecyclableChan struct {
	// contains filtered or unexported fields
}

func NewRecyclableChan

func NewRecyclableChan(desc string, maxPktCnt uint32, extData any) *RecyclableChan

func (*RecyclableChan) Close

func (c *RecyclableChan) Close() error

func (*RecyclableChan) Desc

func (c *RecyclableChan) Desc() string

func (*RecyclableChan) ExtData

func (c *RecyclableChan) ExtData() any

func (*RecyclableChan) Flag1

func (c *RecyclableChan) Flag1() int32

func (*RecyclableChan) Flag2

func (c *RecyclableChan) Flag2() int32

func (*RecyclableChan) IsClosed

func (c *RecyclableChan) IsClosed() bool

func (*RecyclableChan) IsReadReady

func (c *RecyclableChan) IsReadReady() bool

func (*RecyclableChan) Read

func (c *RecyclableChan) Read(b []byte) (n int, err error)

func (*RecyclableChan) ReadPacket

func (c *RecyclableChan) ReadPacket() (b []byte, err error)

func (*RecyclableChan) ReadStream

func (c *RecyclableChan) ReadStream(b []byte) (n int, err error)

func (*RecyclableChan) SetExtData

func (c *RecyclableChan) SetExtData(extData any)

func (*RecyclableChan) SetFlag1

func (c *RecyclableChan) SetFlag1(flag1 int32)

func (*RecyclableChan) SetFlag2

func (c *RecyclableChan) SetFlag2(flag2 int32)

func (*RecyclableChan) SetOnReadReady

func (c *RecyclableChan) SetOnReadReady(callback func()) *RecyclableChan

func (*RecyclableChan) SetReadingAsPkt

func (c *RecyclableChan) SetReadingAsPkt(asPkt bool) *RecyclableChan

func (*RecyclableChan) SetShouldDropWhileError

func (c *RecyclableChan) SetShouldDropWhileError(should bool) *RecyclableChan

func (*RecyclableChan) Write

func (c *RecyclableChan) Write(data []byte) (n int, err error)

type Result

type Result interface {
	IsOk() bool
	Code() int
	Message() string
	Error() string

	Data() any

	SetMsg(msg string) Result
	AppendMsg(msg string) Result
	AppendErr(msg string, err error) Result

	SetData(data any) Result

	IsEqual(other Result) bool
}

func NewResult

func NewResult(code int, message string, data any) Result

func UnmarshalJson

func UnmarshalJson(data []byte) (error, Result)

type State3

type State3 int
var (
	None  State3 = 0
	Doing State3 = 1
	Done  State3 = 2
)

Directories

Path Synopsis
sm4
spr
ref

Jump to

Keyboard shortcuts

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