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:
|
||||
version: latest
|
||||
|
||||
- name: Static Check
|
||||
uses: dominikh/staticcheck-action@v1.2.0
|
||||
with:
|
||||
install-go: false
|
||||
version: "2022.1"
|
||||
|
||||
- name: Tests
|
||||
run: |
|
||||
go test $(go list ./...)
|
||||
|
@ -21,10 +21,8 @@ linters:
|
||||
disable-all: true
|
||||
fast: false
|
||||
enable:
|
||||
#- bodyclose
|
||||
#- deadcode
|
||||
#- depguard
|
||||
#- dogsled
|
||||
- bodyclose
|
||||
- durationcheck
|
||||
- gofmt
|
||||
- goimports
|
||||
- errcheck
|
||||
@ -32,18 +30,16 @@ linters:
|
||||
- exhaustive
|
||||
- bidichk
|
||||
- gocritic
|
||||
#- gosimple
|
||||
- gosimple
|
||||
- govet
|
||||
- ineffassign
|
||||
#- nolintlint
|
||||
#- rowserrcheck
|
||||
#- staticcheck
|
||||
- structcheck
|
||||
#- stylecheck
|
||||
- staticcheck
|
||||
- stylecheck
|
||||
- unconvert
|
||||
#- unparam
|
||||
#- unused
|
||||
- varcheck
|
||||
- usestdlibvars
|
||||
- unparam
|
||||
- unused
|
||||
- whitespace
|
||||
- prealloc
|
||||
- predeclared
|
||||
|
@ -733,11 +733,11 @@ func (bot *CQBot) ConvertContentMessage(content []global.MSG, sourceType message
|
||||
case *message.GroupImageElement:
|
||||
img.Flash = flash
|
||||
img.EffectID = id
|
||||
switch data["subType"].(type) {
|
||||
switch sub := data["subType"].(type) {
|
||||
case int64:
|
||||
img.ImageBizType = message.ImageBizType(data["subType"].(int64))
|
||||
default:
|
||||
img.ImageBizType = message.ImageBizType(data["subType"].(uint32))
|
||||
img.ImageBizType = message.ImageBizType(sub)
|
||||
case uint32:
|
||||
img.ImageBizType = message.ImageBizType(sub)
|
||||
}
|
||||
case *message.FriendImageElement:
|
||||
img.Flash = flash
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
@ -52,7 +51,7 @@ func GetBytes(url string) ([]byte, error) {
|
||||
defer func() {
|
||||
_ = reader.Close()
|
||||
}()
|
||||
return ioutil.ReadAll(reader)
|
||||
return io.ReadAll(reader)
|
||||
}
|
||||
|
||||
// DownloadFile 将给定URL对应的文件下载至给定Path
|
||||
@ -62,7 +61,7 @@ func DownloadFile(url, path string, limit int64, headers map[string]string) erro
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -112,7 +111,7 @@ func DownloadFileMultiThreading(url, path string, limit int64, threadCount int,
|
||||
}
|
||||
return errUnsupportedMultiThreading
|
||||
}
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -132,23 +131,21 @@ func DownloadFileMultiThreading(url, path string, limit int64, threadCount int,
|
||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||
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 {
|
||||
return ErrOverSize
|
||||
}
|
||||
return copyStream(resp.Body)
|
||||
}
|
||||
if resp.StatusCode == 206 {
|
||||
if resp.StatusCode == http.StatusPartialContent {
|
||||
contentLength = resp.ContentLength
|
||||
if limit > 0 && resp.ContentLength > limit {
|
||||
return ErrOverSize
|
||||
}
|
||||
blockSize := func() int64 {
|
||||
blockSize := contentLength
|
||||
if contentLength > 1024*1024 {
|
||||
return (contentLength / int64(threadCount)) - 10
|
||||
blockSize = (contentLength / int64(threadCount)) - 10
|
||||
}
|
||||
return contentLength
|
||||
}()
|
||||
if blockSize == contentLength {
|
||||
return copyStream(resp.Body)
|
||||
}
|
||||
@ -170,7 +167,7 @@ func DownloadFileMultiThreading(url, path string, limit int64, threadCount int,
|
||||
}
|
||||
// 下载分块
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -291,7 +288,7 @@ func (g *gzipCloser) Close() error {
|
||||
|
||||
// HTTPGetReadCloser 从 Http url 获取 io.ReadCloser
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -356,13 +356,13 @@ func (c *HTTPClient) onBotPushEvent(e *coolq.Event) {
|
||||
for i := uint64(0); i <= c.MaxRetries; i++ {
|
||||
// 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
|
||||
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 {
|
||||
log.Warnf("上报 Event 数据到 %v 时创建请求失败: %v", c.addr, err)
|
||||
return
|
||||
}
|
||||
req.Header = header
|
||||
res, err = c.client.Do(req)
|
||||
res, err = c.client.Do(req) // nolint:bodyclose
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ func (l *lambdaResponseWriter) flush() error {
|
||||
Body: body,
|
||||
})
|
||||
|
||||
r, _ := http.NewRequest("POST", cli.responseURL, buffer)
|
||||
r, _ := http.NewRequest(http.MethodPost, cli.responseURL, buffer)
|
||||
do, err := cli.client.Do(r)
|
||||
if err != nil {
|
||||
return err
|
||||
|
Loading…
x
Reference in New Issue
Block a user