mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-04 19:17:37 +08:00
all: fix golangci-lint
This commit is contained in:
parent
933bdee18e
commit
656dc6b103
6
.github/workflows/golint.yml
vendored
6
.github/workflows/golint.yml
vendored
@ -19,12 +19,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
version: latest
|
version: latest
|
||||||
|
|
||||||
- name: Static Check
|
|
||||||
uses: dominikh/staticcheck-action@v1.2.0
|
|
||||||
with:
|
|
||||||
install-go: false
|
|
||||||
version: "2022.1"
|
|
||||||
|
|
||||||
- name: Tests
|
- name: Tests
|
||||||
run: |
|
run: |
|
||||||
go test $(go list ./...)
|
go test $(go list ./...)
|
||||||
|
@ -21,10 +21,8 @@ linters:
|
|||||||
disable-all: true
|
disable-all: true
|
||||||
fast: false
|
fast: false
|
||||||
enable:
|
enable:
|
||||||
#- bodyclose
|
- bodyclose
|
||||||
#- deadcode
|
- durationcheck
|
||||||
#- depguard
|
|
||||||
#- dogsled
|
|
||||||
- gofmt
|
- gofmt
|
||||||
- goimports
|
- goimports
|
||||||
- errcheck
|
- errcheck
|
||||||
@ -32,18 +30,16 @@ linters:
|
|||||||
- exhaustive
|
- exhaustive
|
||||||
- bidichk
|
- bidichk
|
||||||
- gocritic
|
- gocritic
|
||||||
#- gosimple
|
- gosimple
|
||||||
- govet
|
- govet
|
||||||
- ineffassign
|
- ineffassign
|
||||||
#- nolintlint
|
#- nolintlint
|
||||||
#- rowserrcheck
|
- staticcheck
|
||||||
#- staticcheck
|
- stylecheck
|
||||||
- structcheck
|
|
||||||
#- stylecheck
|
|
||||||
- unconvert
|
- unconvert
|
||||||
#- unparam
|
- usestdlibvars
|
||||||
#- unused
|
- unparam
|
||||||
- varcheck
|
- unused
|
||||||
- whitespace
|
- whitespace
|
||||||
- prealloc
|
- prealloc
|
||||||
- predeclared
|
- predeclared
|
||||||
|
@ -733,11 +733,11 @@ func (bot *CQBot) ConvertContentMessage(content []global.MSG, sourceType message
|
|||||||
case *message.GroupImageElement:
|
case *message.GroupImageElement:
|
||||||
img.Flash = flash
|
img.Flash = flash
|
||||||
img.EffectID = id
|
img.EffectID = id
|
||||||
switch data["subType"].(type) {
|
switch sub := data["subType"].(type) {
|
||||||
case int64:
|
case int64:
|
||||||
img.ImageBizType = message.ImageBizType(data["subType"].(int64))
|
img.ImageBizType = message.ImageBizType(sub)
|
||||||
default:
|
case uint32:
|
||||||
img.ImageBizType = message.ImageBizType(data["subType"].(uint32))
|
img.ImageBizType = message.ImageBizType(sub)
|
||||||
}
|
}
|
||||||
case *message.FriendImageElement:
|
case *message.FriendImageElement:
|
||||||
img.Flash = flash
|
img.Flash = flash
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@ -52,7 +51,7 @@ func GetBytes(url string) ([]byte, error) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
_ = reader.Close()
|
_ = reader.Close()
|
||||||
}()
|
}()
|
||||||
return ioutil.ReadAll(reader)
|
return io.ReadAll(reader)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DownloadFile 将给定URL对应的文件下载至给定Path
|
// DownloadFile 将给定URL对应的文件下载至给定Path
|
||||||
@ -62,7 +61,7 @@ func DownloadFile(url, path string, limit int64, headers map[string]string) erro
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -112,7 +111,7 @@ func DownloadFileMultiThreading(url, path string, limit int64, threadCount int,
|
|||||||
}
|
}
|
||||||
return errUnsupportedMultiThreading
|
return errUnsupportedMultiThreading
|
||||||
}
|
}
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -132,23 +131,21 @@ func DownloadFileMultiThreading(url, path string, limit int64, threadCount int,
|
|||||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||||
return errors.New("response status unsuccessful: " + strconv.FormatInt(int64(resp.StatusCode), 10))
|
return errors.New("response status unsuccessful: " + strconv.FormatInt(int64(resp.StatusCode), 10))
|
||||||
}
|
}
|
||||||
if resp.StatusCode == 200 {
|
if resp.StatusCode == http.StatusOK {
|
||||||
if limit > 0 && resp.ContentLength > limit {
|
if limit > 0 && resp.ContentLength > limit {
|
||||||
return ErrOverSize
|
return ErrOverSize
|
||||||
}
|
}
|
||||||
return copyStream(resp.Body)
|
return copyStream(resp.Body)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == 206 {
|
if resp.StatusCode == http.StatusPartialContent {
|
||||||
contentLength = resp.ContentLength
|
contentLength = resp.ContentLength
|
||||||
if limit > 0 && resp.ContentLength > limit {
|
if limit > 0 && resp.ContentLength > limit {
|
||||||
return ErrOverSize
|
return ErrOverSize
|
||||||
}
|
}
|
||||||
blockSize := func() int64 {
|
blockSize := contentLength
|
||||||
if contentLength > 1024*1024 {
|
if contentLength > 1024*1024 {
|
||||||
return (contentLength / int64(threadCount)) - 10
|
blockSize = (contentLength / int64(threadCount)) - 10
|
||||||
}
|
}
|
||||||
return contentLength
|
|
||||||
}()
|
|
||||||
if blockSize == contentLength {
|
if blockSize == contentLength {
|
||||||
return copyStream(resp.Body)
|
return copyStream(resp.Body)
|
||||||
}
|
}
|
||||||
@ -170,7 +167,7 @@ func DownloadFileMultiThreading(url, path string, limit int64, threadCount int,
|
|||||||
}
|
}
|
||||||
// 下载分块
|
// 下载分块
|
||||||
downloadBlock := func(block *BlockMetaData) error {
|
downloadBlock := func(block *BlockMetaData) error {
|
||||||
req, _ := http.NewRequest("GET", url, nil)
|
req, _ := http.NewRequest(http.MethodGet, url, nil)
|
||||||
file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0o666)
|
file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0o666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -291,7 +288,7 @@ func (g *gzipCloser) Close() error {
|
|||||||
|
|
||||||
// HTTPGetReadCloser 从 Http url 获取 io.ReadCloser
|
// HTTPGetReadCloser 从 Http url 获取 io.ReadCloser
|
||||||
func HTTPGetReadCloser(url string) (io.ReadCloser, error) {
|
func HTTPGetReadCloser(url string) (io.ReadCloser, error) {
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -356,13 +356,13 @@ func (c *HTTPClient) onBotPushEvent(e *coolq.Event) {
|
|||||||
for i := uint64(0); i <= c.MaxRetries; i++ {
|
for i := uint64(0); i <= c.MaxRetries; i++ {
|
||||||
// see https://stackoverflow.com/questions/31337891/net-http-http-contentlength-222-with-body-length-0
|
// see https://stackoverflow.com/questions/31337891/net-http-http-contentlength-222-with-body-length-0
|
||||||
// we should create a new request for every single post trial
|
// we should create a new request for every single post trial
|
||||||
req, err = http.NewRequest("POST", c.addr, bytes.NewReader(e.JSONBytes()))
|
req, err = http.NewRequest(http.MethodGet, c.addr, bytes.NewReader(e.JSONBytes()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("上报 Event 数据到 %v 时创建请求失败: %v", c.addr, err)
|
log.Warnf("上报 Event 数据到 %v 时创建请求失败: %v", c.addr, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
req.Header = header
|
req.Header = header
|
||||||
res, err = c.client.Do(req)
|
res, err = c.client.Do(req) // nolint:bodyclose
|
||||||
if err == nil {
|
if err == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ func (l *lambdaResponseWriter) flush() error {
|
|||||||
Body: body,
|
Body: body,
|
||||||
})
|
})
|
||||||
|
|
||||||
r, _ := http.NewRequest("POST", cli.responseURL, buffer)
|
r, _ := http.NewRequest(http.MethodPost, cli.responseURL, buffer)
|
||||||
do, err := cli.client.Do(r)
|
do, err := cli.client.Do(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user