Documentation ¶
Index ¶
- Constants
- Variables
- func Clamp[T Ordered](value T, min T, max T) T
- func ClientIPHeader(header http.Header) *net.IPAddr
- func ClientIPRequest(req *http.Request) *net.IPAddr
- func ClientTCPIPHeader(header http.Header) *net.TCPAddr
- func Compact[T comparable](collection []T) []T
- func Contains[T comparable](collection []T, value T) bool
- func Count[T comparable](collection []T, value T) (count int)
- func CountValues[T comparable](collection []T) map[T]int
- func CreatePid() bool
- func CronAddFunc(spec string, cmd func()) (int, error)
- func Daemon()
- func DefaultAntsPool() *ants.Pool
- func Exit(code int)
- func ExitWait()
- func Exiting() bool
- func GenTraceID() int64
- func HandlePanic()
- func HandlePanic2(callback func())
- func HandlePanicWithCaller(caller *CallerDesc)
- func IndexOf[T comparable](collection []T, element T) int
- func IsMatch(pattern, str string) bool
- func IsSorted[T Ordered](collection []T) bool
- func LastIndexOf[T comparable](collection []T, element T) int
- func LocalIP() (net.IP, error)
- func LocalIPString() string
- func LogCtx(e *zerolog.Event, ctx context.Context) *zerolog.Event
- func LogHttpBody(e *zerolog.Event, header http.Header, logkey string, data []byte, limit int) *zerolog.Event
- func LogHttpInterface(e *zerolog.Event, header http.Header, logkey string, body interface{}, ...) *zerolog.Event
- func Min[T Ordered](collection []T) T
- func ParseIP(addr net.Addr) string
- func RandFloat32() float32
- func RandFloat64() float64
- func RandInt() int
- func RandInt31() int32
- func RandInt31n(n int32) int32
- func RandInt31nm(n, m int32) int32
- func RandInt31nm2(n, m int32) int32
- func RandInt63() int64
- func RandInt63n(n int64) int64
- func RandInt63nm(n, m int64) int64
- func RandInt63nm2(n, m int64) int64
- func RandIntn(n int) int
- func RandIntnm(n, m int) int
- func RandIntnm2(n, m int) int
- func RandShuffle(n int, swap func(i, j int))
- func RandShuffleSlice[T any](collection []T) []T
- func RandString(size int) string
- func RandString2(size int, charset []byte) string
- func RandUint32() uint32
- func RandUint64() uint64
- func RegExit(fn func(os.Signal))
- func Replace[T comparable](collection []T, old T, new T, n int) []T
- func ReplaceAll[T comparable](collection []T, old T, new T) []T
- func Reverse[T any](collection []T) []T
- func Slice[T any](collection []T, start int, end int) []T
- func Submit(task func()) error
- func SubmitProcess(task func()) error
- func Sum[T Float | Integer | Complex](collection []T) T
- func WaitProcess(timeout time.Duration)
- type CallerDesc
- type Complex
- type CtxKey
- type Float
- type Integer
- type Ordered
- type RecvMsger
- type SendMsger
- type Sequence
- type Signed
- type TestHeatBeatReq
- type TestHeatBeatResp
- type TestMsg
- type TestMsgBody
- type TestMsgHead
- type Unsigned
Constants ¶
View Source
const CtxKey_nolog = CtxKey("nolog") // 不打印日志,错误日志还会打印 值:不受限制 一般写1
View Source
const CtxKey_traceId = CtxKey("traceId") // context产生时,设置的唯一ID,用来链路追踪
Variables ¶
View Source
var ( LowerCaseLettersCharset = []byte("abcdefghijklmnopqrstuvwxyz") UpperCaseLettersCharset = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZ") LettersCharset = append(LowerCaseLettersCharset, UpperCaseLettersCharset...) NumbersCharset = []byte("0123456789") AlphanumericCharset = append(LettersCharset, NumbersCharset...) SpecialCharset = []byte("!@#$%^&*()_+-=[]{}|;':\",./<>?") AllCharset = append(AlphanumericCharset, SpecialCharset...) )
View Source
var ( TestHeatBeatReqMsg = &TestMsg{ TestMsgHead: TestMsgHead{ Msgid: 1, }, BodyMsg: &TestHeatBeatReq{Data: string("heatreqmsg")}, } TestHeatBeatRespMsg = &TestMsg{ TestMsgHead: TestMsgHead{ Msgid: 2, }, BodyMsg: &TestHeatBeatResp{Data: string("heatrespmsg")}, } TestRegMsgID = func(msgType reflect.Type) string { m, ok := reflect.New(msgType).Interface().(TestMsgBody) if ok { return strconv.Itoa(int(m.MsgID())) } return "" } )
Functions ¶
func Compact ¶
func Compact[T comparable](collection []T) []T
func Contains ¶
func Contains[T comparable](collection []T, value T) bool
func Count ¶
func Count[T comparable](collection []T, value T) (count int)
func CountValues ¶
func CountValues[T comparable](collection []T) map[T]int
func GenTraceID ¶
func GenTraceID() int64
func HandlePanic2 ¶
func HandlePanic2(callback func())
func HandlePanicWithCaller ¶
func HandlePanicWithCaller(caller *CallerDesc)
func IndexOf ¶
func IndexOf[T comparable](collection []T, element T) int
func LastIndexOf ¶
func LastIndexOf[T comparable](collection []T, element T) int
func LocalIPString ¶
func LocalIPString() string
func LogHttpBody ¶
func LogHttpBody(e *zerolog.Event, header http.Header, logkey string, data []byte, limit int) *zerolog.Event
打印http相关的内容日志,细节待完善
func LogHttpInterface ¶
func RandShuffle ¶
func RandShuffleSlice ¶
func RandShuffleSlice[T any](collection []T) []T
func RandString2 ¶
func Replace ¶
func Replace[T comparable](collection []T, old T, new T, n int) []T
func ReplaceAll ¶
func ReplaceAll[T comparable](collection []T, old T, new T) []T
Types ¶
type CallerDesc ¶
type CallerDesc struct {
// contains filtered or unexported fields
}
func GetCallerDesc ¶
func GetCallerDesc(skip int) *CallerDesc
type Complex ¶
type Complex interface { ~complex64 | ~complex128 }
type RecvMsger ¶
type RecvMsger interface { MsgID() string // 获取msgid BodyUnMarshal(msgType reflect.Type) (interface{}, error) // 根据具体消息类型,解析出消息体 }
接受消息接口,包括消息头和消息体结构
type SendMsger ¶
type SendMsger interface { MsgID() string // 获取msgid MsgMarshal() ([]byte, error) // 编码整个消息,返回的[]byte用来发送数据 }
发送消息接口
type Sequence ¶
type Sequence struct {
// contains filtered or unexported fields
}
协成池调用任务队列 保证任务顺序执行
type TestHeatBeatReq ¶
type TestHeatBeatReq struct {
Data string `json:"data,omitempty"` // 消息体就是一个字符串
}
func (*TestHeatBeatReq) Marshal ¶
func (m *TestHeatBeatReq) Marshal() ([]byte, error)
func (*TestHeatBeatReq) MsgID ¶
func (m *TestHeatBeatReq) MsgID() uint32
func (*TestHeatBeatReq) UnMarshal ¶
func (m *TestHeatBeatReq) UnMarshal(buf []byte) error
type TestHeatBeatResp ¶
type TestHeatBeatResp struct {
Data string `json:"data,omitempty"` // 消息体就是一个字符串
}
func (*TestHeatBeatResp) Marshal ¶
func (m *TestHeatBeatResp) Marshal() ([]byte, error)
func (*TestHeatBeatResp) MsgID ¶
func (m *TestHeatBeatResp) MsgID() uint32
func (*TestHeatBeatResp) UnMarshal ¶
func (m *TestHeatBeatResp) UnMarshal(buf []byte) error
type TestMsg ¶
type TestMsg struct { TestMsgHead // 根据方向不一样,填充的字段不一样 Data []byte // 接受数据时填充 BodyMsg TestMsgBody // 发送数据填充 }
通用的消息测试使用
func (*TestMsg) BodyUnMarshal ¶
func (*TestMsg) MarshalZerologObject ¶
func (*TestMsg) MsgMarshal ¶
type TestMsgBody ¶
type TestMsgHead ¶
Click to show internal directories.
Click to hide internal directories.