base

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2021 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package base ...

Index

Constants

View Source
const (
	// ErrorTypeConfig ...
	ErrorTypeConfig = ErrorType(1)
	// ErrorTypeNet ...
	ErrorTypeNet = ErrorType(2)
	// ErrorTypeAction ...
	ErrorTypeAction = ErrorType(3)
	// ErrorTypeDevelop ...
	ErrorTypeDevelop = ErrorType(4)
	// ErrorTypeKernel ...
	ErrorTypeKernel = ErrorType(5)
	// ErrorTypeSecurity ..
	ErrorTypeSecurity = ErrorType(6)
)
View Source
const (
	// ErrorLevelInfo ...
	ErrorLevelInfo = ErrorLevel(1 << 0)
	// ErrorLevelWarn ...
	ErrorLevelWarn = ErrorLevel(1 << 1)
	// ErrorLevelError ...
	ErrorLevelError = ErrorLevel(1 << 2)
	// ErrorLevelFatal ...
	ErrorLevelFatal = ErrorLevel(1 << 3)
	// ErrorLogAll ...
	ErrorLogAll = ErrorLevelInfo |
		ErrorLevelWarn |
		ErrorLevelError |
		ErrorLevelFatal
)
View Source
const ErrNetClosingSuffix = "use of closed network connection"

ErrNetClosingSuffix ...

Variables

View Source
var (
	// ErrStream ...
	ErrStream = DefineSecurityError(
		generalErrorSeg|1,
		ErrorLevelWarn,
		"stream error",
	)

	// ErrUnsupportedValue ...
	ErrUnsupportedValue = DefineDevelopError(
		generalErrorSeg|2,
		ErrorLevelError,
		"",
	)

	// ErrServiceName ... *
	ErrServiceName = DefineDevelopError(
		generalErrorSeg|3,
		ErrorLevelFatal,
		"",
	)

	// ErrServiceIsNil ... *
	ErrServiceIsNil = DefineDevelopError(
		generalErrorSeg|4,
		ErrorLevelFatal,
		"service is nil",
	)

	// ErrServiceOverflow ... *
	ErrServiceOverflow = DefineDevelopError(
		generalErrorSeg|5,
		ErrorLevelFatal,
		"",
	)

	// ErrActionName ... *
	ErrActionName = DefineDevelopError(
		generalErrorSeg|6,
		ErrorLevelFatal,
		"",
	)

	// ErrActionHandler ... *
	ErrActionHandler = DefineDevelopError(
		generalErrorSeg|7,
		ErrorLevelFatal,
		"",
	)

	// ErrActionCloseTimeout ... *
	ErrActionCloseTimeout = DefineDevelopError(
		generalErrorSeg|8,
		ErrorLevelError,
		"",
	)

	// ErrAction ...
	ErrAction = DefineActionError(
		generalErrorSeg|9,
		ErrorLevelError,
		"",
	)

	// ErrActionPanic ...
	ErrActionPanic = DefineDevelopError(
		generalErrorSeg|10,
		ErrorLevelFatal,
		"",
	)

	// ErrTargetNotExist ...
	ErrTargetNotExist = DefineSecurityError(
		generalErrorSeg|11,
		ErrorLevelError,
		"",
	)

	// ErrCallOverflow ...
	ErrCallOverflow = DefineSecurityError(
		generalErrorSeg|12,
		ErrorLevelError,
		"",
	)

	// ErrArgumentsNotMatch ...
	ErrArgumentsNotMatch = DefineSecurityError(
		generalErrorSeg|13,
		ErrorLevelError,
		"",
	)

	// ErrRuntimeIllegalInCurrentGoroutine ...
	ErrRuntimeIllegalInCurrentGoroutine = DefineDevelopError(
		generalErrorSeg|14,
		ErrorLevelFatal,
		"Runtime is illegal in current goroutine",
	)

	// ErrRuntimeReplyHasBeenCalled ...
	ErrRuntimeReplyHasBeenCalled = DefineDevelopError(
		generalErrorSeg|15,
		ErrorLevelError,
		"Runtime.Reply has been called before",
	)

	// ErrRuntimePostEndpoint ...
	ErrRuntimePostEndpoint = DefineDevelopError(
		generalErrorSeg|16,
		ErrorLevelFatal,
		"Runtime.Post endpoint parse error",
	)

	// ErrRuntimeExternalReturn ...
	ErrRuntimeExternalReturn = DefineDevelopError(
		generalErrorSeg|17,
		ErrorLevelError,
		"action must be return through Runtime.OK or Runtime.Error",
	)

	// ErrRTArrayIndexOverflow ...
	ErrRTArrayIndexOverflow = DefineDevelopError(
		generalErrorSeg|18,
		ErrorLevelFatal,
		"",
	)

	// ErrRTMapNameNotFound ...
	ErrRTMapNameNotFound = DefineDevelopError(
		generalErrorSeg|19,
		ErrorLevelFatal,
		"",
	)

	// ErrNumOfThreadsIsWrong ... *
	ErrNumOfThreadsIsWrong = DefineConfigError(
		generalErrorSeg|20,
		ErrorLevelFatal,
		"numOfThreads is wrong",
	)

	// ErrThreadBufferSizeIsWrong ... *
	ErrThreadBufferSizeIsWrong = DefineConfigError(
		generalErrorSeg|21,
		ErrorLevelFatal,
		"threadBufferSize is wrong",
	)

	// ErrMaxNodeDepthIsWrong ... *
	ErrMaxNodeDepthIsWrong = DefineConfigError(
		generalErrorSeg|22,
		ErrorLevelFatal,
		"maxNodeDepth is wrong",
	)

	// ErrCacheMkdirAll ... *
	ErrCacheMkdirAll = DefineConfigError(
		generalErrorSeg|23,
		ErrorLevelFatal,
		"create directory error",
	)

	// ErrCacheWriteFile ... *
	ErrCacheWriteFile = DefineConfigError(
		generalErrorSeg|24,
		ErrorLevelFatal,
		"write to file error",
	)
)
View Source
var (
	// ErrFnCacheIllegalKindString ... *
	ErrFnCacheIllegalKindString = DefineKernelError(
		coreErrorSeg|1,
		ErrorLevelFatal,
		"",
	)

	// ErrFnCacheDuplicateKindString ... *
	ErrFnCacheDuplicateKindString = DefineKernelError(
		coreErrorSeg|2,
		ErrorLevelFatal,
		"",
	)

	// ErrProcessorMaxCallDepthIsWrong ... *
	ErrProcessorMaxCallDepthIsWrong = DefineKernelError(
		coreErrorSeg|4,
		ErrorLevelFatal,
		"maxCallDepth is wrong",
	)

	// ErrProcessorNodeMetaIsNil ... *
	ErrProcessorNodeMetaIsNil = DefineKernelError(
		coreErrorSeg|5,
		ErrorLevelFatal,
		"node meta is nil",
	)

	// ErrProcessorActionMetaIsNil ... *
	ErrProcessorActionMetaIsNil = DefineKernelError(
		coreErrorSeg|6,
		ErrorLevelFatal,
		"action meta is nil",
	)

	// ErrThreadEvalFatal ...
	ErrThreadEvalFatal = DefineKernelError(
		coreErrorSeg|7,
		ErrorLevelFatal,
		"",
	)

	// ErrProcessorIsNotRunning ... *
	ErrProcessorIsNotRunning = DefineKernelError(
		coreErrorSeg|8,
		ErrorLevelFatal,
		"processor is not running",
	)

	// ErrLogOpenFile ...
	ErrLogOpenFile = DefineKernelError(
		coreErrorSeg|9,
		ErrorLevelError,
		"",
	)

	// ErrLogCloseFile ...
	ErrLogCloseFile = DefineKernelError(
		coreErrorSeg|11,
		ErrorLevelError,
		"",
	)
)
View Source
var (
	// ErrServerAlreadyRunning ...
	ErrServerAlreadyRunning = DefineConfigError(
		serverErrorSeg|1,
		ErrorLevelFatal,
		"it is already running",
	)

	// ErrServerNotRunning ...
	ErrServerNotRunning = DefineConfigError(
		serverErrorSeg|2,
		ErrorLevelFatal,
		"it is not running",
	)

	// ErrServerNoListenersAvailable ...
	ErrServerNoListenersAvailable = DefineConfigError(
		serverErrorSeg|3,
		ErrorLevelFatal,
		"no listeners available on the server",
	)

	// ErrServerSessionNotFound ...
	ErrServerSessionNotFound = DefineConfigError(
		serverErrorSeg|4,
		ErrorLevelWarn,
		"server session not found",
	)

	// ErrServerSessionSeedOverflows ...
	ErrServerSessionSeedOverflows = DefineConfigError(
		serverErrorSeg|5,
		ErrorLevelWarn,
		"server session seed overflows",
	)
)
View Source
var (
	// ErrClientTimeout ...
	ErrClientTimeout = DefineNetError(
		clientErrorSeg|1,
		ErrorLevelWarn,
		"timeout",
	)

	// ErrClientConfig ...
	ErrClientConfig = DefineConfigError(
		clientErrorSeg|2,
		ErrorLevelWarn,
		"client config error",
	)
)
View Source
var (
	// ErrRouterIDInvalid ...
	ErrRouterIDInvalid = DefineNetError(
		routerErrorSeg|1,
		ErrorLevelFatal,
		"",
	)

	// ErrRouterConnDial ...
	ErrRouterConnDial = DefineNetError(
		routerErrorSeg|2,
		ErrorLevelWarn,
		"",
	)

	// ErrRouterConnConnect ...
	ErrRouterConnConnect = DefineNetError(
		routerErrorSeg|3,
		ErrorLevelFatal,
		"",
	)

	// ErrRouterConnRead ...
	ErrRouterConnRead = DefineNetError(
		routerErrorSeg|4,
		ErrorLevelWarn,
		"",
	)

	// ErrRouterConnWrite ...
	ErrRouterConnWrite = DefineNetError(
		routerErrorSeg|5,
		ErrorLevelWarn,
		"",
	)

	// ErrRouterConnProtocol ...
	ErrRouterConnProtocol = DefineNetError(
		routerErrorSeg|6,
		ErrorLevelWarn,
		"",
	)

	// ErrRouterConnListen ...
	ErrRouterConnListen = DefineNetError(
		routerErrorSeg|7,
		ErrorLevelFatal,
		"",
	)

	// ErrRouterConnClose ...
	ErrRouterConnClose = DefineNetError(
		routerErrorSeg|8,
		ErrorLevelFatal,
		"",
	)
)
View Source
var (
	// ErrUnsupportedProtocol ...
	ErrUnsupportedProtocol = DefineNetError(
		goAdapterErrorSeg|1,
		ErrorLevelFatal,
		"",
	)

	// ErrSyncTCPServerServiceListen ...
	ErrSyncTCPServerServiceListen = DefineNetError(
		goAdapterErrorSeg|2,
		ErrorLevelFatal,
		"",
	)

	// ErrSyncTCPServerServiceAccept ...
	ErrSyncTCPServerServiceAccept = DefineNetError(
		goAdapterErrorSeg|3,
		ErrorLevelFatal,
		"",
	)

	// ErrSyncTCPServerServiceClose ...
	ErrSyncTCPServerServiceClose = DefineNetError(
		goAdapterErrorSeg|4,
		ErrorLevelFatal,
		"",
	)

	// ErrSyncWSServerServiceListen ...
	ErrSyncWSServerServiceListen = DefineNetError(
		goAdapterErrorSeg|5,
		ErrorLevelFatal,
		"",
	)

	// ErrSyncWSServerServiceUpgrade ...
	ErrSyncWSServerServiceUpgrade = DefineNetError(
		goAdapterErrorSeg|6,
		ErrorLevelFatal,
		"",
	)

	// ErrSyncWSServerServiceServe ...
	ErrSyncWSServerServiceServe = DefineNetError(
		goAdapterErrorSeg|7,
		ErrorLevelFatal,
		"",
	)

	// ErrSyncWSServerServiceClose ...
	ErrSyncWSServerServiceClose = DefineNetError(
		goAdapterErrorSeg|8,
		ErrorLevelFatal,
		"",
	)

	// ErrSyncClientServiceDial ...
	ErrSyncClientServiceDial = DefineNetError(
		goAdapterErrorSeg|9,
		ErrorLevelWarn,
		"",
	)

	// ErrConnClose ...
	ErrConnClose = DefineNetError(
		goAdapterErrorSeg|10,
		ErrorLevelWarn,
		"",
	)

	// ErrConnRead ...
	ErrConnRead = DefineNetError(
		goAdapterErrorSeg|11,
		ErrorLevelWarn,
		"",
	)

	// ErrConnWrite ...
	ErrConnWrite = DefineNetError(
		goAdapterErrorSeg|12,
		ErrorLevelWarn,
		"",
	)

	// ErrOnFillWriteFatal ...
	ErrOnFillWriteFatal = DefineKernelError(
		goAdapterErrorSeg|13,
		ErrorLevelFatal,
		"kernel error",
	)
)

Functions

func AddFileLine

func AddFileLine(header string, skip uint) string

AddFileLine ...

func AddPrefixPerLine

func AddPrefixPerLine(text string, prefix string) string

AddPrefixPerLine ...

func BytesToStringUnsafe

func BytesToStringUnsafe(bytes []byte) (ret string)

BytesToStringUnsafe ...

func ConcatString

func ConcatString(args ...string) string

ConcatString ...

func ConvertOrdinalToString

func ConvertOrdinalToString(n uint) string

ConvertOrdinalToString ...

func ConvertToIsoDateString

func ConvertToIsoDateString(date time.Time) string

ConvertToIsoDateString convert time.Time to iso string return format "2019-09-09T09:47:16.180+08:00"

func DecryptSessionEndpoint

func DecryptSessionEndpoint(sessionEndpoint string) (uint64, uint64, bool)

DecryptSessionEndpoint ...

func EncryptSessionEndpoint

func EncryptSessionEndpoint(gatewayID uint64, sessionID uint64) (string, bool)

EncryptSessionEndpoint ...

func GetClientTLSConfig added in v0.0.3

func GetClientTLSConfig(
	verifyServerCert bool,
	caFiles []string,
) (*tls.Config, error)

GetClientTLSConfig ...

func GetFileLine

func GetFileLine(skip uint) string

GetFileLine ...

func GetRandString

func GetRandString(strLen int) string

GetRandString get random string

func GetSeed

func GetSeed() int64

GetSeed get int64 seed, it is goroutine safety

func GetServerTLSConfig added in v0.0.3

func GetServerTLSConfig(certFile string, keyFile string) (*tls.Config, error)

GetServerTLSConfig ...

func IsNil

func IsNil(val interface{}) (ret bool)

IsNil ...

func IsTCPPortOccupied

func IsTCPPortOccupied(port uint16) bool

IsTCPPortOccupied ...

func IsTimeApproximatelyEqual

func IsTimeApproximatelyEqual(t1 time.Time, t2 time.Time) bool

IsTimeApproximatelyEqual ...

func MaxInt

func MaxInt(v1 int, v2 int) int

MaxInt ...

func MaxInt64 added in v0.0.2

func MaxInt64(v1 int64, v2 int64) int64

MaxInt64 ...

func MinInt

func MinInt(v1 int, v2 int) int

MinInt ...

func MinInt64 added in v0.0.2

func MinInt64(v1 int64, v2 int64) int64

MinInt64 ...

func NewAssert

func NewAssert(t interface{ Fail() }) func(args ...interface{}) *Assert

NewAssert ...

func NewLogger added in v0.0.2

func NewLogger(isLogToScreen bool, outFile string) (*Logger, *Error)

NewLogger ...

func PublishPanic

func PublishPanic(err *Error)

PublishPanic ...

func ReadFromFile

func ReadFromFile(filePath string) (string, error)

ReadFromFile ...

func RunWithCatchPanic

func RunWithCatchPanic(fn func()) (ret interface{})

RunWithCatchPanic ...

func RunWithLogOutput

func RunWithLogOutput(fn func()) string

RunWithLogOutput ...

func StringToBytesUnsafe

func StringToBytesUnsafe(s string) (ret []byte)

StringToBytesUnsafe ...

func TimeNow

func TimeNow() time.Time

TimeNow get now nanoseconds from 1970-01-01

func TimeNowISOString

func TimeNowISOString() string

TimeNowISOString get now iso string like this: 2019-09-09T09:47:16.180+08:00

func WaitWhileRunning added in v0.0.2

func WaitWhileRunning(
	startNS int64,
	isRunning func() bool,
	duration time.Duration,
)

WaitWhileRunning ...

Types

type Assert

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

Assert ...

func (*Assert) Equals added in v0.0.2

func (p *Assert) Equals(args ...interface{})

Equals ...

func (*Assert) Fail

func (p *Assert) Fail(reason string)

Fail ...

func (*Assert) IsFalse

func (p *Assert) IsFalse()

IsFalse ...

func (*Assert) IsNil

func (p *Assert) IsNil()

IsNil ...

func (*Assert) IsNotNil

func (p *Assert) IsNotNil()

IsNotNil ...

func (*Assert) IsTrue

func (p *Assert) IsTrue()

IsTrue ...

type Error

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

Error ...

func DefineActionError

func DefineActionError(idx ErrorIndex, level ErrorLevel, msg string) *Error

DefineActionError ...

func DefineConfigError

func DefineConfigError(idx ErrorIndex, level ErrorLevel, msg string) *Error

DefineConfigError ...

func DefineDevelopError

func DefineDevelopError(idx ErrorIndex, level ErrorLevel, msg string) *Error

DefineDevelopError ...

func DefineKernelError

func DefineKernelError(idx ErrorIndex, level ErrorLevel, msg string) *Error

DefineKernelError ...

func DefineNetError

func DefineNetError(idx ErrorIndex, level ErrorLevel, msg string) *Error

DefineNetError ...

func DefineSecurityError

func DefineSecurityError(idx ErrorIndex, level ErrorLevel, msg string) *Error

DefineSecurityError ...

func NewError

func NewError(code uint32, message string) *Error

NewError ...

func RunWithSubscribePanic

func RunWithSubscribePanic(fn func()) *Error

RunWithSubscribePanic ...

func (*Error) AddDebug

func (p *Error) AddDebug(debug string) *Error

AddDebug ...

func (*Error) Error

func (p *Error) Error() string

func (*Error) GetCode

func (p *Error) GetCode() uint32

GetCode ...

func (*Error) GetIndex

func (p *Error) GetIndex() ErrorIndex

GetIndex ...

func (*Error) GetLevel

func (p *Error) GetLevel() ErrorLevel

GetLevel ...

func (*Error) GetMessage

func (p *Error) GetMessage() string

GetMessage ...

func (*Error) GetType

func (p *Error) GetType() ErrorType

GetType ...

func (*Error) ReportString added in v0.0.2

func (p *Error) ReportString(machineID uint64, sessionID uint64) string

func (*Error) Standardize

func (p *Error) Standardize() *Error

Standardize ...

type ErrorIndex

type ErrorIndex uint16

ErrorIndex ...

type ErrorLevel

type ErrorLevel uint8

ErrorLevel ...

type ErrorType

type ErrorType uint8

ErrorType ...

type GlobalID added in v0.0.2

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

GlobalID ...

func NewGlobalID added in v0.0.2

func NewGlobalID() *GlobalID

NewGlobalID ...

func (*GlobalID) Close added in v0.0.2

func (p *GlobalID) Close()

Close ...

func (*GlobalID) GetID added in v0.0.2

func (p *GlobalID) GetID() uint64

GetID ...

type IORCService

type IORCService interface {
	Open() bool
	Run()
	Close() bool
}

IORCService ...

type Logger added in v0.0.2

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

Logger ...

func (*Logger) Close added in v0.0.2

func (p *Logger) Close() *Error

Close ...

func (*Logger) Log added in v0.0.2

func (p *Logger) Log(str string)

Log ...

type ORCManager

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

ORCManager ...

func NewORCManager

func NewORCManager() *ORCManager

NewORCManager ...

func (*ORCManager) Close

func (p *ORCManager) Close(willClose func(), didClose func()) bool

Close close the ORCManager willClose will be called immediately if ORCManager is opened correctly. didClose will be called when ORCManager is opened correctly and all onRun functions (if present) have completed

func (*ORCManager) IsClosed added in v0.0.2

func (p *ORCManager) IsClosed() bool

func (*ORCManager) IsClosing added in v0.0.2

func (p *ORCManager) IsClosing() bool

func (*ORCManager) IsRunning added in v0.0.2

func (p *ORCManager) IsRunning() bool

func (*ORCManager) Open

func (p *ORCManager) Open(onOpen func() bool) bool

Open ...

func (*ORCManager) Run

func (p *ORCManager) Run(onRuns ...func(isRunning func() bool))

Run ...

type PanicSubscription

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

PanicSubscription ...

func SubscribePanic

func SubscribePanic(onPanic func(*Error)) *PanicSubscription

SubscribePanic ...

func (*PanicSubscription) Close

func (p *PanicSubscription) Close() bool

Close ...

type PerformanceIndicator

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

PerformanceIndicator ...

func NewPerformanceIndicator

func NewPerformanceIndicator() *PerformanceIndicator

NewPerformanceIndicator ...

func (*PerformanceIndicator) Calculate

func (p *PerformanceIndicator) Calculate(now time.Time) (int64, time.Duration)

Calculate ...

func (*PerformanceIndicator) Count

func (p *PerformanceIndicator) Count(duration time.Duration, success bool)

Count ...

type SpeedCounter

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

SpeedCounter count the speed

func NewSpeedCounter

func NewSpeedCounter() *SpeedCounter

NewSpeedCounter ...

func (*SpeedCounter) Calculate

func (p *SpeedCounter) Calculate(
	now time.Time,
) (int64, time.Duration)

Calculate ...

func (*SpeedCounter) Count

func (p *SpeedCounter) Count() int64

Count ...

func (*SpeedCounter) Total

func (p *SpeedCounter) Total() int64

Total ...

type StringBuilder

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

StringBuilder high performance string builder

func NewStringBuilder

func NewStringBuilder() *StringBuilder

NewStringBuilder create a string builder

func (*StringBuilder) AppendByte

func (p *StringBuilder) AppendByte(byte byte)

AppendByte append byte to the buffer

func (*StringBuilder) AppendBytes

func (p *StringBuilder) AppendBytes(bytes []byte)

AppendBytes append bytes to the buffer

func (*StringBuilder) AppendString

func (p *StringBuilder) AppendString(str string)

AppendString append a string to string builder

func (*StringBuilder) IsEmpty

func (p *StringBuilder) IsEmpty() bool

IsEmpty return is the string builder is empty

func (*StringBuilder) Merge

func (p *StringBuilder) Merge(builder *StringBuilder)

Merge write a string builder to current string builder

func (*StringBuilder) Release

func (p *StringBuilder) Release()

Release release the builder

func (*StringBuilder) Reset

func (p *StringBuilder) Reset()

Reset reset the builder

func (*StringBuilder) String

func (p *StringBuilder) String() string

String get the builder string

type SyncPool

type SyncPool = sync.Pool

SyncPool ...

type SyncPoolDebug

type SyncPoolDebug struct {
	New func() interface{}
	// contains filtered or unexported fields
}

SyncPoolDebug ...

func (*SyncPoolDebug) Get

func (p *SyncPoolDebug) Get() interface{}

Get ...

func (*SyncPoolDebug) Put

func (p *SyncPoolDebug) Put(value interface{})

Put ...

Jump to

Keyboard shortcuts

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