1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 03:23:49 +08:00

internal/download: add comments

make lint happy!
This commit is contained in:
wdvxdr 2022-10-13 21:34:08 +08:00
parent f4117bfb70
commit 997cdceb7a

View File

@ -1,3 +1,4 @@
// Package download provide download utility functions
package download package download
import ( import (
@ -39,6 +40,7 @@ var ErrOverSize = errors.New("oversize")
// UserAgent HTTP请求时使用的UA // UserAgent HTTP请求时使用的UA
const UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.66" const UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.66"
// Request is a file download request
type Request struct { type Request struct {
URL string URL string
Header map[string]string Header map[string]string
@ -87,6 +89,7 @@ func (r Request) Bytes() ([]byte, error) {
return io.ReadAll(rd) return io.ReadAll(rd)
} }
// JSON 发送GET请求 并转换响应为JSON
func (r Request) JSON() (gjson.Result, error) { func (r Request) JSON() (gjson.Result, error) {
rd, err := r.body() rd, err := r.body()
if err != nil { if err != nil {
@ -112,6 +115,7 @@ func writeToFile(reader io.ReadCloser, path string) error {
return err return err
} }
// WriteToFile 下载到制定目录
func (r Request) WriteToFile(path string) error { func (r Request) WriteToFile(path string) error {
rd, err := r.body() rd, err := r.body()
if err != nil { if err != nil {
@ -121,6 +125,7 @@ func (r Request) WriteToFile(path string) error {
return writeToFile(rd, path) return writeToFile(rd, path)
} }
// WriteToFileMultiThreading 多线程下载到制定目录
func (r Request) WriteToFileMultiThreading(path string, thread int) error { func (r Request) WriteToFileMultiThreading(path string, thread int) error {
if thread < 2 { if thread < 2 {
return r.WriteToFile(path) return r.WriteToFile(path)