From 570bcb47c09fe03d3f8fb7aab458afd83cb71bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=87=E8=91=A9=E3=81=AE=E7=81=B5=E6=A2=A6?= <415551921@qq.com> Date: Sun, 24 Mar 2024 01:00:56 +0800 Subject: [PATCH] lint --- .github/workflows/build-v2.yml | 5 ++++- account.go | 18 +++++++++--------- client.go | 2 +- dynamic.go | 2 +- fav.go | 14 +++++++------- live.go | 2 +- login.go | 3 ++- message.go | 8 ++++---- video.go | 8 +++++--- 9 files changed, 34 insertions(+), 28 deletions(-) diff --git a/.github/workflows/build-v2.yml b/.github/workflows/build-v2.yml index 877ee0e..5574b47 100644 --- a/.github/workflows/build-v2.yml +++ b/.github/workflows/build-v2.yml @@ -22,7 +22,10 @@ jobs: uses: golangci/golangci-lint-action@v4 with: version: latest - args: --out-${NO_FUTURE}format line-number --timeout 3m0s + args: --out-${NO_FUTURE}format line-number --timeout 3m0s -p bugs -p error -p performance -D unused -D gosmopolitan + + - name: Test + run: go test -v ./... - name: Build run: go build -v ./... diff --git a/account.go b/account.go index 3036be7..9645c61 100644 --- a/account.go +++ b/account.go @@ -7,14 +7,14 @@ import ( // AccountInformation 自己账号相关的简单信息 type AccountInformation struct { - Mid int64 `json:"mid"` //我的mid - Uname string `json:"uname"` //我的昵称 - Userid string `json:"userid"` //我的用户名 - Sign string `json:"sign"` //我的签名 - Birthday string `json:"birthday"` //我的生日 - Sex string `json:"sex"` //我的性别 - NickFree bool `json:"nick_free"` //false:设置过昵称 true:未设置昵称 - Rank string `json:"rank"` //我的会员等级 + Mid int64 `json:"mid"` // 我的mid + Uname string `json:"uname"` // 我的昵称 + Userid string `json:"userid"` // 我的用户名 + Sign string `json:"sign"` // 我的签名 + Birthday string `json:"birthday"` // 我的生日 + Sex string `json:"sex"` // 我的性别 + NickFree bool `json:"nick_free"` // false:设置过昵称 true:未设置昵称 + Rank string `json:"rank"` // 我的会员等级 } // GetAccountInformation 获取我的信息 无参数 @@ -34,5 +34,5 @@ func (c *Client) GetAccountInformation() (*AccountInformation, error) { err = json.Unmarshal(data, &accountInfo) - return &accountInfo, err + return &accountInfo, errors.WithStack(err) } diff --git a/client.go b/client.go index ae62de9..e7e3dd6 100644 --- a/client.go +++ b/client.go @@ -71,7 +71,7 @@ func (c *Client) GetCookies() []*http.Cookie { // SetCookies 设置Cookies。有些功能必须登录之后才能使用,设置Cookies可以代替登录。 func (c *Client) SetCookies(cookies []*http.Cookie) { c.cookies = cookies - var cookieStrings []string + cookieStrings := make([]string, 0, len(cookies)) for _, cookie := range c.cookies { cookieStrings = append(cookieStrings, cookie.String()) } diff --git a/dynamic.go b/dynamic.go index 8b534e6..681df71 100644 --- a/dynamic.go +++ b/dynamic.go @@ -540,7 +540,7 @@ func (c *Client) UploadDynamicBfs(fileName string, file io.Reader, category stri ImageHeight int `json:"image_height"` } err = json.Unmarshal(ret, &data) - return data.ImageUrl, Size{Width: data.ImageWidth, Height: data.ImageHeight}, err + return data.ImageUrl, Size{Width: data.ImageWidth, Height: data.ImageHeight}, errors.WithStack(err) } // CreateDynamic 发表纯文本动态 diff --git a/fav.go b/fav.go index eb28a8c..07e8f2c 100644 --- a/fav.go +++ b/fav.go @@ -39,7 +39,7 @@ func (c *Client) AddFavourFolder(title, intro string, privacy bool, cover string } var ret *FavourFolderInfo err = json.Unmarshal(data, &ret) - return ret, err + return ret, errors.WithStack(err) } // EditFavourFolder 修改收藏夹 @@ -76,7 +76,7 @@ func (c *Client) EditFavourFolder(mediaId int, title, intro string, privacy bool } var ret *FavourFolderInfo err = json.Unmarshal(data, &ret) - return ret, err + return ret, errors.WithStack(err) } // DeleteFavourFolder 删除收藏夹 @@ -251,7 +251,7 @@ func (c *Client) GetFavourFolderInfo(mediaId int) (*FavourFolderInfo, error) { } var ret *FavourFolderInfo err = json.Unmarshal(data, &ret) - return ret, err + return ret, errors.WithStack(err) } type AllFavourFolderInfo struct { @@ -287,7 +287,7 @@ func (c *Client) GetAllFavourFolderInfo(upMid, attrType, rid int) (*AllFavourFol } var ret *AllFavourFolderInfo err = json.Unmarshal(data, &ret) - return ret, err + return ret, errors.WithStack(err) } type FavourInfo struct { @@ -339,7 +339,7 @@ func (c *Client) GetFavourInfo(resources []Resource, platform string) ([]*Favour } var ret []*FavourInfo err = json.Unmarshal(data, &ret) - return ret, err + return ret, errors.WithStack(err) } type FavourList struct { @@ -435,7 +435,7 @@ func (c *Client) GetFavourList(mediaId, tid int, keyword, order string, searchTy } var ret *FavourList err = json.Unmarshal(data, &ret) - return ret, err + return ret, errors.WithStack(err) } type FavourId struct { @@ -462,5 +462,5 @@ func (c *Client) GetFavourIds(mediaId int, platform string) ([]*FavourId, error) } var ret []*FavourId err = json.Unmarshal(data, &ret) - return ret, err + return ret, errors.WithStack(err) } diff --git a/live.go b/live.go index 1188efd..7ac44e8 100644 --- a/live.go +++ b/live.go @@ -75,7 +75,7 @@ type RoomInfo struct { BgPic string `json:"bg_pic"` UseOldArea bool `json:"use_old_area"` } `json:"frame"` - //Badge interface{} `json:"badge"` + // Badge interface{} `json:"badge"` MobileFrame struct { Name string `json:"name"` Value string `json:"value"` diff --git a/login.go b/login.go index 35a1f62..18cb722 100644 --- a/login.go +++ b/login.go @@ -220,7 +220,8 @@ type QRCode struct { // Encode a QRCode and return a raw PNG image. func (result *QRCode) Encode() ([]byte, error) { - return qrcode.Encode(result.Url, qrcode.Medium, 256) + buf, err := qrcode.Encode(result.Url, qrcode.Medium, 256) + return buf, errors.WithStack(err) } // Print the QRCode in the console diff --git a/message.go b/message.go index 77fdc20..172df3c 100644 --- a/message.go +++ b/message.go @@ -30,7 +30,7 @@ func (c *Client) GetUnreadMessage() (*UnreadMessage, error) { } var ret *UnreadMessage err = json.Unmarshal(data, &ret) - return ret, err + return ret, errors.WithStack(err) } type UnreadPrivateMessage struct { @@ -51,7 +51,7 @@ func (c *Client) GetUnreadPrivateMessage() (*UnreadPrivateMessage, error) { } var ret *UnreadPrivateMessage err = json.Unmarshal(data, &ret) - return ret, err + return ret, errors.WithStack(err) } var deviceId string @@ -229,7 +229,7 @@ func (c *Client) GetSessionMessages(talkerId, sessionType, size int, mobiApp str } var ret *SessionMessages err = json.Unmarshal(data, &ret) - return ret, err + return ret, errors.WithStack(err) } type SessionList struct { @@ -301,5 +301,5 @@ func (c *Client) GetSessions(sessionType int, mobiApp string) (*SessionList, err } var ret *SessionList err = json.Unmarshal(data, &ret) - return ret, err + return ret, errors.WithStack(err) } diff --git a/video.go b/video.go index e104f38..910a680 100644 --- a/video.go +++ b/video.go @@ -84,7 +84,7 @@ type VideoInfo struct { NoShare int `json:"no_share"` ArcPay int `json:"arc_pay"` FreeWatch int `json:"free_watch"` - } + } `json:"rights"` Owner struct { // 视频UP主信息 Mid int `json:"mid"` // UP主mid Name string `json:"name"` // UP主昵称 @@ -743,10 +743,11 @@ func (c *Client) FavourVideoByAvid(avid int, addMediaIds, delMediaIds []int) (bo if len(biliJct) == 0 { return false, errors.New("B站登录过期") } - var addMediaIdStr, delMediaIdStr []string + addMediaIdStr := make([]string, 0, len(addMediaIds)) for _, id := range addMediaIds { addMediaIdStr = append(addMediaIdStr, strconv.Itoa(id)) } + delMediaIdStr := make([]string, 0, len(delMediaIds)) for _, id := range delMediaIds { delMediaIdStr = append(delMediaIdStr, strconv.Itoa(id)) } @@ -773,10 +774,11 @@ func (c *Client) FavourVideoByBvid(bvid string, addMediaIds, delMediaIds []int) if len(biliJct) == 0 { return false, errors.New("B站登录过期") } - var addMediaIdStr, delMediaIdStr []string + addMediaIdStr := make([]string, 0, len(addMediaIds)) for _, id := range addMediaIds { addMediaIdStr = append(addMediaIdStr, strconv.Itoa(id)) } + delMediaIdStr := make([]string, 0, len(delMediaIds)) for _, id := range delMediaIds { delMediaIdStr = append(delMediaIdStr, strconv.Itoa(id)) }