Skip to content

Commit

Permalink
all: fix some issue reported by golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
wdvxdr1123 committed Feb 13, 2023
1 parent 2156430 commit 993ec12
Show file tree
Hide file tree
Showing 22 changed files with 71 additions and 103 deletions.
62 changes: 31 additions & 31 deletions binary/jce/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ func NewJceReader(data []byte) *JceReader {
return &JceReader{buf: data}
}

func (r *JceReader) readHead() (hd HeadData, l int) {
hd, l = r.peakHead()
func (r *JceReader) readHead() HeadData {
hd, l := r.peakHead()
r.off += l
return
return hd
}

func (r *JceReader) peakHead() (hd HeadData, l int) {
Expand Down Expand Up @@ -86,7 +86,7 @@ func (r *JceReader) skipField(t byte) {
}

func (r *JceReader) skipNextField() {
hd, _ := r.readHead()
hd := r.readHead()
r.skipField(hd.Type)
}

Expand Down Expand Up @@ -151,18 +151,18 @@ func (r *JceReader) skipToTag(tag int) bool {
}

func (r *JceReader) skipToStructEnd() {
hd, _ := r.readHead()
hd := r.readHead()
for hd.Type != 11 {
r.skipField(hd.Type)
hd, _ = r.readHead()
hd = r.readHead()
}
}

func (r *JceReader) ReadByte(tag int) byte {
if !r.skipToTag(tag) {
return 0
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 12:
return 0
Expand All @@ -181,7 +181,7 @@ func (r *JceReader) ReadInt16(tag int) int16 {
if !r.skipToTag(tag) {
return 0
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 12:
return 0
Expand All @@ -198,7 +198,7 @@ func (r *JceReader) ReadInt32(tag int) int32 {
if !r.skipToTag(tag) {
return 0
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 12:
return 0
Expand All @@ -217,7 +217,7 @@ func (r *JceReader) ReadInt64(tag int) int64 {
if !r.skipToTag(tag) {
return 0
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 12:
return 0
Expand All @@ -238,7 +238,7 @@ func (r *JceReader) ReadFloat32(tag int) float32 {
if !r.skipToTag(tag) {
return 0
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 12:
return 0
Expand All @@ -253,7 +253,7 @@ func (r *JceReader) ReadFloat64(tag int) float64 {
if !r.skipToTag(tag) {
return 0
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 12:
return 0
Expand All @@ -270,7 +270,7 @@ func (r *JceReader) ReadString(tag int) string {
if !r.skipToTag(tag) {
return ""
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 6:
return utils.B2S(r.readBytes(int(r.readByte())))
Expand All @@ -285,7 +285,7 @@ func (r *JceReader) ReadBytes(tag int) []byte {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
Expand All @@ -306,7 +306,7 @@ func (r *JceReader) ReadByteArrArr(tag int) (baa [][]byte) {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
Expand Down Expand Up @@ -373,7 +373,7 @@ func (r *JceReader) ReadJceStruct(obj IJceStruct, tag int) {
if !r.skipToTag(tag) {
return
}
hd, _ := r.readHead()
hd := r.readHead()
if hd.Type != 10 {
return
}
Expand All @@ -385,7 +385,7 @@ func (r *JceReader) ReadMapStrStr(tag int) map[string]string {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 8:
s := r.ReadInt32(0)
Expand All @@ -403,7 +403,7 @@ func (r *JceReader) ReadMapStrByte(tag int) map[string][]byte {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 8:
s := r.ReadInt32(0)
Expand All @@ -422,7 +422,7 @@ func (r *JceReader) ReadMapIntVipInfo(tag int) map[int]*VipInfo {
return nil
}
r.skipHead()
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 8:
s := r.ReadInt32(0)
Expand All @@ -447,7 +447,7 @@ func (r *JceReader) ReadMapStrMapStrByte(tag int) map[string]map[string][]byte {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 8:
s := r.ReadInt32(0)
Expand Down Expand Up @@ -512,7 +512,7 @@ func (r *JceReader) ReadFileStorageServerInfos(tag int) []FileStorageServerInfo
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
Expand All @@ -532,7 +532,7 @@ func (r *JceReader) ReadBigDataIPLists(tag int) []BigDataIPList {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
Expand All @@ -552,7 +552,7 @@ func (r *JceReader) ReadBigDataIPInfos(tag int) []BigDataIPInfo {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
Expand All @@ -572,7 +572,7 @@ func (r *JceReader) ReadOnlineInfos(tag int) []OnlineInfo {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
Expand All @@ -592,7 +592,7 @@ func (r *JceReader) ReadInstanceInfos(tag int) []InstanceInfo {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
Expand All @@ -612,7 +612,7 @@ func (r *JceReader) ReadSsoServerInfos(tag int) []SsoServerInfo {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
Expand All @@ -632,7 +632,7 @@ func (r *JceReader) ReadFriendInfos(tag int) []FriendInfo {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
Expand All @@ -652,7 +652,7 @@ func (r *JceReader) ReadTroopNumbers(tag int) []TroopNumber {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
Expand All @@ -672,7 +672,7 @@ func (r *JceReader) ReadTroopMemberInfos(tag int) []TroopMemberInfo {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
Expand All @@ -692,7 +692,7 @@ func (r *JceReader) ReadPushMessageInfos(tag int) []PushMessageInfo {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
Expand All @@ -712,7 +712,7 @@ func (r *JceReader) ReadSvcDevLoginInfos(tag int) []SvcDevLoginInfo {
if !r.skipToTag(tag) {
return nil
}
hd, _ := r.readHead()
hd := r.readHead()
switch hd.Type {
case 9:
s := r.ReadInt32(0)
Expand Down
2 changes: 1 addition & 1 deletion binary/jce/reader_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package jce

import (
"math/rand"
"crypto/rand"
"reflect"
"strconv"
"sync"
Expand Down
2 changes: 1 addition & 1 deletion binary/writer_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package binary

import (
"math/rand"
"crypto/rand"
"testing"
)

Expand Down
2 changes: 1 addition & 1 deletion client/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ func (c *QQClient) buildGetMessageRequestPacket(flag msg.SyncFlag, msgTime int64
})
}
req := &msg.GetMessageRequest{
SyncFlag: proto.Some(int32(flag)),
SyncFlag: proto.Some(flag),
SyncCookie: cook,
LatestRambleNumber: proto.Int32(20),
OtherRambleNumber: proto.Int32(3),
Expand Down
8 changes: 4 additions & 4 deletions client/c2c_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ func privatePttDecoder(c *QQClient, pMsg *msg.Message, _ network.RequestParams)
if pMsg.Body == nil || pMsg.Body.RichText == nil || pMsg.Body.RichText.Ptt == nil {
return
}
if len(pMsg.Body.RichText.Ptt.Reserve) != 0 {
// m := binary.NewReader(pMsg.Body.RichText.Ptt.Reserve[1:]).ReadTlvMap(1)
// T3 -> timestamp T8 -> voiceType T9 -> voiceLength T10 -> PbReserveStruct
}
// if len(pMsg.Body.RichText.Ptt.Reserve) != 0 {
// m := binary.NewReader(pMsg.Body.RichText.Ptt.Reserve[1:]).ReadTlvMap(1)
// T3 -> timestamp T8 -> voiceType T9 -> voiceLength T10 -> PbReserveStruct
//}
c.PrivateMessageEvent.dispatch(c, c.parsePrivateMessage(pMsg))
}

Expand Down
18 changes: 0 additions & 18 deletions client/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,24 +304,6 @@ func genForwardTemplate(resID, preview, summary string, ts int64, items []*msg.P
}
}

func genLongTemplate(resID, brief string, ts int64) *message.ServiceElement {
limited := func() string {
if ss := []rune(brief); len(ss) > 30 {
return string(ss[:30]) + "…"
}
return brief
}()
template := fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="35" templateID="1" action="viewMultiMsg" brief="%s" m_resid="%s" m_fileName="%d" sourceMsgId="0" url="" flag="3" adverSign="0" multiMsgFlag="1"> <item layout="1"> <title>%s</title> <hr hidden="false" style="0"/> <summary>点击查看完整消息</summary> </item> <source name="聊天记录" icon="" action="" appid="-1"/> </msg>`,
utils.XmlEscape(limited), resID, ts, utils.XmlEscape(limited),
)
return &message.ServiceElement{
Id: 35,
Content: template,
ResId: resID,
SubType: "Long",
}
}

func (c *QQClient) getWebDeviceInfo() (i string) {
qimei := strings.ToLower(utils.RandomString(36))
i += fmt.Sprintf("i=%v&imsi=&mac=%v&m=%v&o=%v&", c.device.IMEI, utils.B2S(c.device.MacAddress), utils.B2S(c.device.Device), utils.B2S(c.device.Version.Release))
Expand Down
2 changes: 1 addition & 1 deletion client/group_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func decodeGroupInfoResponse(c *QQClient, pkt *network.Packet) (any, error) {
func (c *QQClient) uploadGroupHeadPortrait(groupCode int64, img []byte) error {
url := fmt.Sprintf("http://htdata3.qq.com/cgi-bin/httpconn?htcmd=0x6ff0072&ver=5520&ukey=%v&range=0&uin=%v&seq=23&groupuin=%v&filetype=3&imagetype=5&userdata=0&subcmd=1&subver=101&clip=0_0_0_0&filesize=%v",
c.getSKey(), c.Uin, groupCode, len(img))
req, _ := http.NewRequest("POST", url, bytes.NewReader(img))
req, _ := http.NewRequest(http.MethodPost, url, bytes.NewReader(img))
req.Header["User-Agent"] = []string{"Dalvik/2.1.0 (Linux; U; Android 7.1.2; PCRT00 Build/N2G48H)"}
req.Header["Content-Type"] = []string{"multipart/form-data;boundary=****"}
rsp, err := http.DefaultClient.Do(req)
Expand Down
4 changes: 2 additions & 2 deletions client/guild.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ func decodeGuildPushFirstView(c *QQClient, pkt *network.Packet) (any, error) {
c.GuildService.Guilds = append(c.GuildService.Guilds, info)
}
}
if len(firstViewMsg.ChannelMsgs) > 0 { // sync msg
}
// if len(firstViewMsg.ChannelMsgs) > 0 { // sync msg
// }
return nil, nil
}
4 changes: 2 additions & 2 deletions client/guild_eventflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func decodeGuildEventFlowPacket(c *QQClient, pkt *network.Packet) (any, error) {
}
}
if m.Head.ContentHead.SubType.Unwrap() == 2 { // todo: tips?
if common == nil { // empty tips
}
// if common == nil { // empty tips
// }
tipsInfo := &tipsPushInfo{
TinyId: m.Head.RoutingHead.FromTinyid.Unwrap(),
GuildId: m.Head.RoutingHead.GuildId.Unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion client/http_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (c *QQClient) uploadGroupNoticePic(img []byte) (*noticeImage, error) {
fw, _ := w.CreatePart(h)
_, _ = fw.Write(img)
_ = w.Close()
req, err := http.NewRequest("POST", "https://web.qun.qq.com/cgi-bin/announce/upload_img", buf)
req, err := http.NewRequest(http.MethodPost, "https://web.qun.qq.com/cgi-bin/announce/upload_img", buf)
if err != nil {
return nil, errors.Wrap(err, "new request error")
}
Expand Down
2 changes: 1 addition & 1 deletion client/internal/auth/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package auth

import (
"crypto/md5"
"crypto/rand"
"encoding/hex"
"encoding/json"
"math/rand"

"github.com/pkg/errors"

Expand Down
2 changes: 1 addition & 1 deletion client/internal/auth/pow.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func CalcPow(data []byte) []byte {
}
ok = true
dst = tmp.Bytes()
elp = uint32(time.Now().Sub(start).Milliseconds())
elp = uint32(time.Since(start).Milliseconds())
}

w := binary.SelectWriter()
Expand Down
Loading

0 comments on commit 993ec12

Please sign in to comment.