Skip to content

Commit

Permalink
internal/download: add comments
Browse files Browse the repository at this point in the history
make lint happy!
  • Loading branch information
wdvxdr1123 committed Oct 13, 2022
1 parent f4117bf commit 997cdce
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/download/download.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package download provide download utility functions
package download

import (
Expand Down Expand Up @@ -39,6 +40,7 @@ var ErrOverSize = errors.New("oversize")
// 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"

// Request is a file download request
type Request struct {
URL string
Header map[string]string
Expand Down Expand Up @@ -87,6 +89,7 @@ func (r Request) Bytes() ([]byte, error) {
return io.ReadAll(rd)
}

// JSON 发送GET请求, 并转换响应为JSON
func (r Request) JSON() (gjson.Result, error) {
rd, err := r.body()
if err != nil {
Expand All @@ -112,6 +115,7 @@ func writeToFile(reader io.ReadCloser, path string) error {
return err
}

// WriteToFile 下载到制定目录
func (r Request) WriteToFile(path string) error {
rd, err := r.body()
if err != nil {
Expand All @@ -121,6 +125,7 @@ func (r Request) WriteToFile(path string) error {
return writeToFile(rd, path)
}

// WriteToFileMultiThreading 多线程下载到制定目录
func (r Request) WriteToFileMultiThreading(path string, thread int) error {
if thread < 2 {
return r.WriteToFile(path)
Expand Down

0 comments on commit 997cdce

Please sign in to comment.