mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 11:07:40 +08:00
style: fix issues reported by golangci-lint
This commit is contained in:
parent
58e81648e5
commit
8b99d3147e
@ -34,7 +34,7 @@ func (w *JceWriter) WriteByte(b, tag byte) *JceWriter {
|
||||
}
|
||||
|
||||
func (w *JceWriter) WriteBool(b bool, tag byte) {
|
||||
var by byte = 0
|
||||
var by byte
|
||||
if b {
|
||||
by = 1
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ type encoder struct {
|
||||
|
||||
func (msg DynamicProtoMessage) Encode() []byte {
|
||||
en := &encoder{}
|
||||
|
||||
//nolint:staticcheck
|
||||
for id, value := range msg {
|
||||
key := id << 3
|
||||
switch v := value.(type) {
|
||||
|
@ -97,11 +97,12 @@ func (r *Reader) ReadTlvMap(tagSize int) (m TlvMap) {
|
||||
return m
|
||||
}
|
||||
var k uint16
|
||||
if tagSize == 1 {
|
||||
switch tagSize {
|
||||
case 1:
|
||||
k = uint16(r.ReadByte())
|
||||
} else if tagSize == 2 {
|
||||
case 2:
|
||||
k = r.ReadUInt16()
|
||||
} else if tagSize == 4 {
|
||||
case 4:
|
||||
k = uint16(r.ReadInt32())
|
||||
}
|
||||
if k == 255 {
|
||||
|
@ -29,7 +29,7 @@ func (t TEA) Encrypt(src []byte) (dst []byte) {
|
||||
block := binary.BigEndian.Uint64(dst[i:])
|
||||
holder = block ^ iv1
|
||||
iv1 = t.encode(holder)
|
||||
iv1 = iv1 ^ iv2
|
||||
iv1 ^= iv2
|
||||
iv2 = holder
|
||||
binary.BigEndian.PutUint64(dst[i:], iv1)
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package client
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
@ -14,7 +13,6 @@ import (
|
||||
"github.com/Mrs4s/MiraiGo/client/pb/msg"
|
||||
"github.com/Mrs4s/MiraiGo/client/pb/oidb"
|
||||
"github.com/Mrs4s/MiraiGo/client/pb/profilecard"
|
||||
"github.com/Mrs4s/MiraiGo/client/pb/qweb"
|
||||
"github.com/Mrs4s/MiraiGo/client/pb/structmsg"
|
||||
"github.com/Mrs4s/MiraiGo/internal/crypto"
|
||||
"github.com/Mrs4s/MiraiGo/internal/packets"
|
||||
@ -1080,6 +1078,7 @@ func (c *QQClient) buildQuitGroupPacket(groupCode int64) (uint16, []byte) {
|
||||
return seq, packet
|
||||
}
|
||||
|
||||
/* this function is unused
|
||||
// LightAppSvc.mini_app_info.GetAppInfoById
|
||||
func (c *QQClient) buildAppInfoRequestPacket(id string) (uint16, []byte) {
|
||||
seq := c.nextSeq()
|
||||
@ -1099,6 +1098,7 @@ func (c *QQClient) buildAppInfoRequestPacket(id string) (uint16, []byte) {
|
||||
packet := packets.BuildUniPacket(c.Uin, seq, "LightAppSvc.mini_app_info.GetAppInfoById", 1, c.OutGoingPacketSessionId, EmptyBytes, c.sigInfo.d2Key, payload)
|
||||
return seq, packet
|
||||
}
|
||||
*/
|
||||
|
||||
func (c *QQClient) buildWordSegmentationPacket(data []byte) (uint16, []byte) {
|
||||
seq := c.nextSeq()
|
||||
|
@ -95,11 +95,9 @@ type QQClient struct {
|
||||
fileStorageInfo *jce.FileStoragePushFSSvcList
|
||||
|
||||
// message state
|
||||
lastMessageSeq int32
|
||||
msgSvcCache *utils.Cache
|
||||
lastC2CMsgTime int64
|
||||
transCache *utils.Cache
|
||||
lastLostMsg string
|
||||
groupSysMsgCache *GroupSystemMessages
|
||||
groupMsgBuilders sync.Map
|
||||
onlinePushCache *utils.Cache
|
||||
@ -107,7 +105,6 @@ type QQClient struct {
|
||||
groupSeq int32
|
||||
friendSeq int32
|
||||
heartbeatEnabled bool
|
||||
groupDataTransSeq int32
|
||||
highwayApplyUpSeq int32
|
||||
eventHandlers *eventHandlers
|
||||
|
||||
@ -150,6 +147,13 @@ type handlerInfo struct {
|
||||
params requestParams
|
||||
}
|
||||
|
||||
func (h *handlerInfo) getParams() requestParams {
|
||||
if h == nil {
|
||||
return nil
|
||||
}
|
||||
return h.params
|
||||
}
|
||||
|
||||
var decoders = map[string]func(*QQClient, *incomingPacketInfo, []byte) (interface{}, error){
|
||||
"wtlogin.login": decodeLoginResponse,
|
||||
"wtlogin.exchange_emp": decodeExchangeEmpResponse,
|
||||
@ -174,7 +178,6 @@ var decoders = map[string]func(*QQClient, *incomingPacketInfo, []byte) (interfac
|
||||
"OidbSvc.0xd79": decodeWordSegmentation,
|
||||
"OidbSvc.0x990": decodeTranslateResponse,
|
||||
"SummaryCard.ReqSummaryCard": decodeSummaryCardResponse,
|
||||
"LightAppSvc.mini_app_info.GetAppInfoById": decodeAppInfoResponse,
|
||||
}
|
||||
|
||||
func init() {
|
||||
@ -866,10 +869,6 @@ func (c *QQClient) nextQWebSeq() int64 {
|
||||
return atomic.AddInt64(&c.qwebSeq, 1)
|
||||
}
|
||||
|
||||
func (c *QQClient) nextGroupDataTransSeq() int32 {
|
||||
return atomic.AddInt32(&c.groupDataTransSeq, 2)
|
||||
}
|
||||
|
||||
func (c *QQClient) nextHighwayApplySeq() int32 {
|
||||
return atomic.AddInt32(&c.highwayApplyUpSeq, 2)
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ import (
|
||||
"github.com/Mrs4s/MiraiGo/client/pb/msg"
|
||||
"github.com/Mrs4s/MiraiGo/client/pb/oidb"
|
||||
"github.com/Mrs4s/MiraiGo/client/pb/profilecard"
|
||||
"github.com/Mrs4s/MiraiGo/client/pb/qweb"
|
||||
"github.com/Mrs4s/MiraiGo/client/pb/structmsg"
|
||||
"github.com/Mrs4s/MiraiGo/internal/proto"
|
||||
"github.com/Mrs4s/MiraiGo/utils"
|
||||
@ -794,6 +793,7 @@ func decodeWordSegmentation(_ *QQClient, _ *incomingPacketInfo, payload []byte)
|
||||
return nil, errors.New("no word received")
|
||||
}
|
||||
|
||||
/* unused
|
||||
// LightAppSvc.mini_app_info.GetAppInfoById
|
||||
func decodeAppInfoResponse(_ *QQClient, _ *incomingPacketInfo, payload []byte) (interface{}, error) {
|
||||
pkg := qweb.QWebRsp{}
|
||||
@ -809,6 +809,7 @@ func decodeAppInfoResponse(_ *QQClient, _ *incomingPacketInfo, payload []byte) (
|
||||
}
|
||||
return rsp.AppInfo, nil
|
||||
}
|
||||
*/
|
||||
|
||||
func ignoreDecoder(_ *QQClient, _ *incomingPacketInfo, _ []byte) (interface{}, error) {
|
||||
return nil, nil
|
||||
|
@ -22,8 +22,7 @@ import (
|
||||
"github.com/Mrs4s/MiraiGo/utils"
|
||||
)
|
||||
|
||||
type (
|
||||
guildImageUploadResponse struct {
|
||||
type guildImageUploadResponse struct {
|
||||
UploadKey []byte
|
||||
UploadIp []uint32
|
||||
UploadPort []uint32
|
||||
@ -35,7 +34,6 @@ type (
|
||||
ResultCode int32
|
||||
IsExists bool
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
decoders["ImgStore.QQMeetPicUp"] = decodeGuildImageStoreResponse
|
||||
@ -201,20 +199,18 @@ func (s *GuildService) pullChannelMessages(guildId, channelId, beginSeq, endSeq,
|
||||
param.Version = []uint64{eventVersion}
|
||||
}
|
||||
|
||||
withVersionFlag := uint32(0)
|
||||
if eventVersion != 0 {
|
||||
withVersionFlag = 1
|
||||
}
|
||||
directFlag := uint32(0)
|
||||
if direct {
|
||||
directFlag = 1
|
||||
}
|
||||
payload, _ := proto.Marshal(&channel.ChannelMsgReq{
|
||||
ChannelParam: param,
|
||||
WithVersionFlag: proto.Uint32(func() uint32 {
|
||||
if eventVersion != 0 {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}()),
|
||||
DirectMessageFlag: proto.Uint32(func() uint32 {
|
||||
if direct {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}()),
|
||||
WithVersionFlag: &withVersionFlag,
|
||||
DirectMessageFlag: &directFlag,
|
||||
})
|
||||
seq := s.c.nextSeq()
|
||||
packet := packets.BuildUniPacket(s.c.Uin, seq, "trpc.group_pro.synclogic.SyncLogic.GetChannelMsg", 1, s.c.OutGoingPacketSessionId, []byte{}, s.c.sigInfo.d2Key, payload)
|
||||
|
@ -124,10 +124,9 @@ func (c *QQClient) GetGroupHonorInfo(groupCode int64, honorType HonorType) (*Gro
|
||||
/* -------- TextToSpeech -------- */
|
||||
|
||||
func (c *QQClient) GetTts(text string) ([]byte, error) {
|
||||
url := "https://textts.qq.com/cgi-bin/tts"
|
||||
bt, _ := json.Marshal(text)
|
||||
data := fmt.Sprintf(`{"appid": "201908021016","sendUin": %v,"text": %s}`, c.Uin, bt)
|
||||
rsp, err := utils.HttpPostBytesWithCookie(url, []byte(data), c.getCookies())
|
||||
apiUrl := "https://textts.qq.com/cgi-bin/tts"
|
||||
data := fmt.Sprintf(`{"appid": "201908021016","sendUin": %v,"text": %q}`, c.Uin, text)
|
||||
rsp, err := utils.HttpPostBytesWithCookie(apiUrl, []byte(data), c.getCookies())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to post to tts server")
|
||||
}
|
||||
|
@ -32,8 +32,7 @@ func init() {
|
||||
|
||||
var imgWaiter = utils.NewUploadWaiter()
|
||||
|
||||
type (
|
||||
imageUploadResponse struct {
|
||||
type imageUploadResponse struct {
|
||||
UploadKey []byte
|
||||
UploadIp []uint32
|
||||
UploadPort []uint32
|
||||
@ -45,14 +44,13 @@ type (
|
||||
ResultCode int32
|
||||
IsExists bool
|
||||
}
|
||||
)
|
||||
|
||||
func (c *QQClient) UploadGroupImage(groupCode int64, img io.ReadSeeker) (*message.GroupImageElement, error) {
|
||||
_, _ = img.Seek(0, io.SeekStart) // safe
|
||||
fh, length := utils.ComputeMd5AndLength(img)
|
||||
_, _ = img.Seek(0, io.SeekStart)
|
||||
|
||||
key := hex.EncodeToString(fh)
|
||||
key := string(fh)
|
||||
imgWaiter.Wait(key)
|
||||
defer imgWaiter.Done(key)
|
||||
|
||||
|
@ -95,12 +95,13 @@ func decodeMultiApplyDownResponse(_ *QQClient, _ *incomingPacketInfo, payload []
|
||||
return nil, errors.New("not found")
|
||||
}
|
||||
rsp := body.MultimsgApplydownRsp[0]
|
||||
prefix := func() string {
|
||||
|
||||
var prefix string
|
||||
if rsp.MsgExternInfo != nil && rsp.MsgExternInfo.ChannelType == 2 {
|
||||
return "https://ssl.htdata.qq.com"
|
||||
prefix = "https://ssl.htdata.qq.com"
|
||||
} else {
|
||||
prefix = fmt.Sprintf("http://%s:%d", binary.UInt32ToIPV4Address(uint32(rsp.Uint32DownIp[0])), body.MultimsgApplydownRsp[0].Uint32DownPort[0])
|
||||
}
|
||||
return fmt.Sprintf("http://%s:%d", binary.UInt32ToIPV4Address(uint32(rsp.Uint32DownIp[0])), body.MultimsgApplydownRsp[0].Uint32DownPort[0])
|
||||
}()
|
||||
b, err := utils.HttpGetBytes(fmt.Sprintf("%s%s", prefix, string(rsp.ThumbDownPara)), "")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to download by multi apply down")
|
||||
|
@ -75,7 +75,7 @@ func (c *QQClient) ConnectionQualityTest() *ConnectionQualityInfo {
|
||||
}()
|
||||
start := time.Now()
|
||||
if _, err := utils.HttpGetBytes("https://ssl.htdata.qq.com", ""); err == nil {
|
||||
r.LongMessageServerResponseLatency = time.Now().Sub(start).Milliseconds()
|
||||
r.LongMessageServerResponseLatency = time.Since(start).Milliseconds()
|
||||
} else {
|
||||
c.Error("test long message server response latency error: %v", err)
|
||||
r.LongMessageServerResponseLatency = 9999
|
||||
@ -335,12 +335,7 @@ func (c *QQClient) netLoop() {
|
||||
decoded, err = decoder(c, &incomingPacketInfo{
|
||||
SequenceId: pkt.SequenceId,
|
||||
CommandName: pkt.CommandName,
|
||||
Params: func() requestParams {
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return info.params
|
||||
}(),
|
||||
Params: info.getParams(),
|
||||
}, pkt.Payload)
|
||||
if err != nil {
|
||||
c.Debug("decode pkt %v error: %+v", pkt.CommandName, err)
|
||||
|
@ -131,6 +131,7 @@ func (s *TempSessionInfo) SendMessage(m *message.SendingMessage) (*message.TempM
|
||||
}
|
||||
}
|
||||
|
||||
/* this function is unused
|
||||
func (c *QQClient) buildGetOneDayRoamMsgRequest(target, lastMsgTime, random int64, count uint32) (uint16, []byte) {
|
||||
seq := c.nextSeq()
|
||||
req := &msg.PbGetOneDayRoamMsgReq{
|
||||
@ -143,6 +144,7 @@ func (c *QQClient) buildGetOneDayRoamMsgRequest(target, lastMsgTime, random int6
|
||||
packet := packets.BuildUniPacket(c.Uin, seq, "MessageSvc.PbGetOneDayRoamMsg", 1, c.OutGoingPacketSessionId, EmptyBytes, c.sigInfo.d2Key, payload)
|
||||
return seq, packet
|
||||
}
|
||||
*/
|
||||
|
||||
// MessageSvc.PbSendMsg
|
||||
func (c *QQClient) buildFriendSendingPacket(target int64, msgSeq, r, pkgNum, pkgIndex, pkgDiv int32, time int64, m []message.IMessageElement) (uint16, []byte) {
|
||||
|
@ -35,7 +35,7 @@ func (c *QQClient) UploadGroupPtt(groupCode int64, voice io.ReadSeeker) (*messag
|
||||
pttWaiter.Wait(key)
|
||||
defer pttWaiter.Done(key)
|
||||
|
||||
ext := c.buildGroupPttStoreBDHExt(groupCode, fh[:], int32(length), 0, int32(length))
|
||||
ext := c.buildGroupPttStoreBDHExt(groupCode, fh, int32(length), 0, int32(length))
|
||||
rsp, err := c.highwaySession.UploadBDH(highway.BdhInput{
|
||||
CommandID: 29,
|
||||
Body: voice,
|
||||
@ -60,8 +60,8 @@ func (c *QQClient) UploadGroupPtt(groupCode int64, voice io.ReadSeeker) (*messag
|
||||
Ptt: &msg.Ptt{
|
||||
FileType: proto.Int32(4),
|
||||
SrcUin: &c.Uin,
|
||||
FileMd5: fh[:],
|
||||
FileName: proto.String(hex.EncodeToString(fh[:]) + ".amr"),
|
||||
FileMd5: fh,
|
||||
FileName: proto.String(hex.EncodeToString(fh) + ".amr"),
|
||||
FileSize: proto.Int32(int32(length)),
|
||||
GroupFileKey: pkt.TryupPttRsp[0].FileKey,
|
||||
BoolValid: proto.Bool(true),
|
||||
@ -81,7 +81,7 @@ func (c *QQClient) UploadPrivatePtt(target int64, voice io.ReadSeeker) (*message
|
||||
pttWaiter.Wait(key)
|
||||
defer pttWaiter.Done(key)
|
||||
|
||||
ext := c.buildC2CPttStoreBDHExt(target, fh[:], int32(length), int32(length))
|
||||
ext := c.buildC2CPttStoreBDHExt(target, fh, int32(length), int32(length))
|
||||
rsp, err := c.highwaySession.UploadBDH(highway.BdhInput{
|
||||
CommandID: 26,
|
||||
Body: voice,
|
||||
@ -107,8 +107,8 @@ func (c *QQClient) UploadPrivatePtt(target int64, voice io.ReadSeeker) (*message
|
||||
FileType: proto.Int32(4),
|
||||
SrcUin: &c.Uin,
|
||||
FileUuid: pkt.ApplyUploadRsp.Uuid,
|
||||
FileMd5: fh[:],
|
||||
FileName: proto.String(hex.EncodeToString(fh[:]) + ".amr"),
|
||||
FileMd5: fh,
|
||||
FileName: proto.String(hex.EncodeToString(fh) + ".amr"),
|
||||
FileSize: proto.Int32(int32(length)),
|
||||
// Reserve: constructPTTExtraInfo(1, int32(len(voice))), // todo length
|
||||
BoolValid: proto.Bool(true),
|
||||
|
@ -101,15 +101,14 @@ func (c *QQClient) SendGuildMusicShare(guildID, channelID uint64, msg *message.M
|
||||
func (c *QQClient) buildRichMsgSendingPacket(guild uint64, target int64, msg *message.MusicShareElement, sendType uint32) (uint16, []byte) {
|
||||
seq := c.nextSeq()
|
||||
tp := musicType[msg.MusicType] // MusicType
|
||||
msgStyle := uint32(0)
|
||||
if msg.MusicUrl != "" {
|
||||
msgStyle = 4
|
||||
}
|
||||
body := &oidb.DB77ReqBody{
|
||||
AppId: tp.appID,
|
||||
AppType: tp.appType,
|
||||
MsgStyle: func() uint32 {
|
||||
if msg.MusicUrl == "" {
|
||||
return 0
|
||||
}
|
||||
return 4
|
||||
}(),
|
||||
MsgStyle: msgStyle,
|
||||
ClientInfo: &oidb.DB77ClientInfo{
|
||||
Platform: tp.platform,
|
||||
SdkVersion: tp.sdkVersion,
|
||||
|
@ -138,31 +138,26 @@ func (c *QQClient) buildSystemMsgNewGroupPacket(suspicious bool) (uint16, []byte
|
||||
// ProfileService.Pb.ReqSystemMsgAction.Group
|
||||
func (c *QQClient) buildSystemMsgGroupActionPacket(reqID, requester, group int64, msgType int32, isInvite, accept, block bool, reason string) (uint16, []byte) {
|
||||
seq := c.nextSeq()
|
||||
subSrcId := int32(31)
|
||||
groupMsgType := int32(1)
|
||||
if isInvite {
|
||||
subSrcId = 10016
|
||||
groupMsgType = 2
|
||||
}
|
||||
infoType := int32(12)
|
||||
if accept {
|
||||
infoType = 11
|
||||
}
|
||||
req := &structmsg.ReqSystemMsgAction{
|
||||
MsgType: msgType,
|
||||
MsgSeq: reqID,
|
||||
ReqUin: requester,
|
||||
SubType: 1,
|
||||
SrcId: 3,
|
||||
SubSrcId: func() int32 {
|
||||
if isInvite {
|
||||
return 10016
|
||||
}
|
||||
return 31
|
||||
}(),
|
||||
GroupMsgType: func() int32 {
|
||||
if isInvite {
|
||||
return 2
|
||||
}
|
||||
return 1
|
||||
}(),
|
||||
SubSrcId: subSrcId,
|
||||
GroupMsgType: groupMsgType,
|
||||
ActionInfo: &structmsg.SystemMsgActionInfo{
|
||||
Type: func() int32 {
|
||||
if accept {
|
||||
return 11
|
||||
}
|
||||
return 12
|
||||
}(),
|
||||
Type: infoType,
|
||||
GroupCode: group,
|
||||
Blacklist: block,
|
||||
Msg: reason,
|
||||
@ -178,6 +173,10 @@ func (c *QQClient) buildSystemMsgGroupActionPacket(reqID, requester, group int64
|
||||
// ProfileService.Pb.ReqSystemMsgAction.Friend
|
||||
func (c *QQClient) buildSystemMsgFriendActionPacket(reqID, requester int64, accept bool) (uint16, []byte) {
|
||||
seq := c.nextSeq()
|
||||
infoType := int32(3)
|
||||
if accept {
|
||||
infoType = 2
|
||||
}
|
||||
req := &structmsg.ReqSystemMsgAction{
|
||||
MsgType: 1,
|
||||
MsgSeq: reqID,
|
||||
@ -186,12 +185,7 @@ func (c *QQClient) buildSystemMsgFriendActionPacket(reqID, requester int64, acce
|
||||
SrcId: 6,
|
||||
SubSrcId: 7,
|
||||
ActionInfo: &structmsg.SystemMsgActionInfo{
|
||||
Type: func() int32 {
|
||||
if accept {
|
||||
return 2
|
||||
}
|
||||
return 3
|
||||
}(),
|
||||
Type: infoType,
|
||||
Blacklist: false,
|
||||
AddFrdSNInfo: &structmsg.AddFrdSNInfo{},
|
||||
},
|
||||
|
@ -200,12 +200,12 @@ func NewUrlShare(url, title, content, image string) *ServiceElement {
|
||||
}
|
||||
}
|
||||
|
||||
func NewRichXml(template string, ResId int64) *ServiceElement {
|
||||
if ResId == 0 {
|
||||
ResId = 60 // 默认值60
|
||||
func NewRichXml(template string, resID int64) *ServiceElement {
|
||||
if resID == 0 {
|
||||
resID = 60 // 默认值60
|
||||
}
|
||||
return &ServiceElement{
|
||||
Id: int32(ResId),
|
||||
Id: int32(resID),
|
||||
Content: template,
|
||||
SubType: "xml",
|
||||
}
|
||||
|
@ -138,8 +138,7 @@ func (e *GroupImageElement) Pack() (r []*msg.Elem) {
|
||||
return []*msg.Elem{elem}
|
||||
}
|
||||
|
||||
func (e *FriendImageElement) Pack() (r []*msg.Elem) {
|
||||
r = []*msg.Elem{}
|
||||
func (e *FriendImageElement) Pack() []*msg.Elem {
|
||||
image := &msg.NotOnlineImage{
|
||||
FilePath: &e.ImageId,
|
||||
ResId: &e.ImageId,
|
||||
|
@ -423,12 +423,10 @@ func ParseMessageElems(elems []*msg.Elem) []IMessageElement {
|
||||
if isOk := strings.Contains(content, "<?xml"); isOk {
|
||||
res = append(res, NewRichXml(content, int64(elem.RichMsg.GetServiceId())))
|
||||
continue
|
||||
} else {
|
||||
if json.Valid(utils.S2B(content)) {
|
||||
} else if json.Valid(utils.S2B(content)) {
|
||||
res = append(res, NewRichJson(content))
|
||||
continue
|
||||
}
|
||||
}
|
||||
res = append(res, NewText(content))
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +68,6 @@ func SendICMPRequest(addr *net.IPAddr, seq int) (int64, error) {
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "read icmp conn error")
|
||||
}
|
||||
duration := time.Now().Sub(start).Milliseconds()
|
||||
duration := time.Since(start).Milliseconds()
|
||||
return duration, nil
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ func RandomString(len int) string {
|
||||
|
||||
func RandomStringRange(length int, str string) string {
|
||||
sb := strings.Builder{}
|
||||
sb.Grow(length)
|
||||
for i := 0; i < length; i++ {
|
||||
sb.WriteByte(str[rand.Intn(len(str))])
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user