util

package
v0.0.0-...-4e7898a Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2021 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertProtoToMessageType

func ConvertProtoToMessageType(protoMsgType protos.MsgType) message.Type

ConvertProtoToMessageType converts a protos.MsgType to a message.Type

func CtxWithDefaultLogger

func CtxWithDefaultLogger(ctx context.Context, route string, userID uint32) context.Context

CtxWithDefaultLogger inserts a default logger on ctx to be used on handlers and remotes. If using logrus, userId, route and requestId will be added as fields. Otherwise the pitaya logger will be used as it is.

func CtxWithPlayerLogger

func CtxWithPlayerLogger(ctx context.Context, userID uint32) context.Context

func FileExists

func FileExists(filename string) bool

FileExists tells if a file exists

func FuncTimeCost

func FuncTimeCost() func()

FuncTimeCost calc function time cost

func GetContextFromRequest

func GetContextFromRequest(req *protos.Request, serverID string) (context.Context, error)

GetContextFromRequest gets the context from a request

func GetErrorFromPayload

func GetErrorFromPayload(serializer serialize.Serializer, payload []byte) error

GetErrorFromPayload gets the error from payload

func GetErrorPayload

func GetErrorPayload(serializer serialize.Serializer, err error) ([]byte, error)

GetErrorPayload creates and serializes an error payload

func GetErrorProtoPayload

func GetErrorProtoPayload(serializer serialize.Serializer, err error) ([]byte, message.Type, error)

func Pcall

func Pcall(method reflect.Method, args []reflect.Value) (rets interface{}, err error)

Pcall calls a method that returns an interface and an error and recovers in case of panic

func RecoverPanic

func RecoverPanic()

func SerializeOrRaw

func SerializeOrRaw(serializer serialize.Serializer, typ message.Type, v interface{}) ([]byte, error)

SerializeOrRaw serializes the interface if its not an array of bytes already

func SliceContainsString

func SliceContainsString(slice []string, str string) bool

SliceContainsString returns true if a slice contains the string

func StartSpanFromRequest

func StartSpanFromRequest(
	ctx context.Context,
	serverID, route string,
) context.Context

StartSpanFromRequest starts a tracing span from the request

Types

type Pool

type Pool struct {
	Queue chan int
	Wg    *sync.WaitGroup
}

func NewPool

func NewPool(cap, total int) *Pool

创建并发控制池, 设置并发数量与总数量

func (*Pool) AddOne

func (p *Pool) AddOne()

向并发队列中添加一个

func (*Pool) DelOne

func (p *Pool) DelOne()

并发队列中释放一个, 并从总数量中减去一个

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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