Skip to content

Commit

Permalink
chore: fix golangci-lint issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
syhily committed Nov 9, 2022
1 parent 0f1e337 commit 5e14247
Show file tree
Hide file tree
Showing 19 changed files with 121 additions and 128 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.18'
go-version: '1.19'
check-latest: true
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.18'
go-version: '1.19'
check-latest: true
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
Expand Down
18 changes: 7 additions & 11 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ linters-settings:
linters:
disable-all: true

# Re-enable the comments after golangci-lint supports go 1.18
## https://github.com/golangci/golangci-lint/issues/2649
enable:
# - bodyclose
- deadcode
- bodyclose
- depguard
- dogsled
- dupl
Expand All @@ -60,22 +58,20 @@ linters:
- goimports
- goprintffuncname
- gosec
# - gosimple
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
# - noctx
- noctx
- nolintlint
# - staticcheck
# - structcheck
# - stylecheck
- staticcheck
- stylecheck
- typecheck
- unconvert
# - unparam
# - unused
- varcheck
- unparam
- unused
- whitespace

run:
Expand Down
4 changes: 2 additions & 2 deletions cmd/talebook/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func register() {
config.UserAgent = regConf.userAgent
client := spider.NewClient(config)

website := spider.GenerateUrl(regConf.website, "/api/user/sign_up")
referer := spider.GenerateUrl(regConf.website, "/signup")
website := spider.GenerateURL(regConf.website, "/api/user/sign_up")
referer := spider.GenerateURL(regConf.website, "/signup")
form := spider.Form{
spider.Field{Key: "username", Value: regConf.username},
spider.Field{Key: "password", Value: regConf.password},
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/bookstairs/bookhunter

go 1.18
go 1.19

require (
github.com/PuerkitoBio/goquery v1.8.0
Expand Down
2 changes: 1 addition & 1 deletion pkg/progress/prgress.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (storage *Progress) SaveBookID(bookID int64) error {
defer storage.lock.Unlock()

if bookID > int64(storage.progress.Len()) {
return errors.New(fmt.Sprintf("invalid book id: %d", bookID))
return fmt.Errorf("invalid book id: %d", bookID)
}

i := uint(bookID - 1)
Expand Down
14 changes: 7 additions & 7 deletions pkg/spider/aliyundrive.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,30 @@ func ResolveAliYunDrive(client *Client, url, passcode string, formats ...string)
return resolveAliYunDrive(client, url, passcode, formats)
}

func resolveAliYunDrive(client *Client, shareUrl string, sharePwd string, formats []string) ([]string, error) {
shareId := strings.TrimPrefix(shareUrl, "https://www.aliyundrive.com/s/")
func resolveAliYunDrive(client *Client, shareURL string, sharePwd string, formats []string) ([]string, error) {
shareID := strings.TrimPrefix(shareURL, "https://www.aliyundrive.com/s/")
sharePwd = strings.TrimSpace(sharePwd)

if drive == nil {
drive = NewAliYunDrive(client, AliyunConfig)
}
return resolveShare(drive, shareId, sharePwd, formats)
return resolveShare(drive, shareID, sharePwd, formats)
}

func resolveShare(drive *aliyundrive.AliYunDrive, shareId string, sharePwd string, formats []string) ([]string, error) {
token, err := drive.GetShredToken(shareId, sharePwd)
func resolveShare(drive *aliyundrive.AliYunDrive, shareID string, sharePwd string, formats []string) ([]string, error) {
token, err := drive.GetShredToken(shareID, sharePwd)
if err != nil {
return nil, err
}
shareFiles, err := drive.GetShare(shareId, token.ShareToken)
shareFiles, err := drive.GetShare(shareID, token.ShareToken)
if err != nil {
return nil, err
}
var links []string
for item := range shareFiles {
for _, format := range formats {
if strings.EqualFold(item.FileExtension, format) {
url, err := drive.GetFileDownloadUrl(token.ShareToken, shareId, item.FileId)
url, err := drive.GetFileDownloadURL(token.ShareToken, shareID, item.FileID)
if err != nil {
return nil, err
}
Expand Down
17 changes: 7 additions & 10 deletions pkg/spider/aliyundrive/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ import (
)

const (
Authorization = "authorization"
ContentType = "content-type"
UserAgent = "User-Agent"

ContentType = "content-type"
UserAgent = "User-Agent"
ContentTypeJSON = "application/json"

Bearer = "bearer"

BaseURL = "https://auth.aliyundrive.com"
ApiURL = "https://api.aliyundrive.com"
APIHost = "https://api.aliyundrive.com"

AccessTokenPrefix = "at:"
RefreshTokenPrefix = "rt:"
Expand All @@ -26,9 +22,9 @@ const (

V2AccountToken = BaseURL + "/v2/account/token"
V2ShareLinkGetShareToken = BaseURL + "/v2/share_link/get_share_token"
V2FileGetShareLinkDownloadUrl = ApiURL + "/v2/file/get_share_link_download_url"
V3FileList = ApiURL + "/adrive/v3/file/list"
V2ShareLinkGetShareByAnonymous = ApiURL + "/adrive/v2/share_link/get_share_by_anonymous"
V2FileGetShareLinkDownloadURL = APIHost + "/v2/file/get_share_link_download_url"
V3FileList = APIHost + "/adrive/v3/file/list"
V2ShareLinkGetShareByAnonymous = APIHost + "/adrive/v2/share_link/get_share_by_anonymous"
)

type AliYunDrive struct {
Expand All @@ -42,5 +38,6 @@ func HcHook(_ *resty.Client, req *http.Request) error {
req.Header.Del(xEmptyContentType)
req.Header.Set(ContentType, "")
}

return nil
}
48 changes: 24 additions & 24 deletions pkg/spider/aliyundrive/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"github.com/bookstairs/bookhunter/pkg/log"
)

func (ali AliYunDrive) GetAnonymousShare(shareId string) (*GetShareInfoResponse, error) {
func (ali AliYunDrive) GetAnonymousShare(shareID string) (*GetShareInfoResponse, error) {
downloadResp, err := ali.Client.R().
SetAuthToken(ali.GetAuthorizationToken()).
SetBody(GetShareInfoRequest{ShareId: shareId}).
SetBody(GetShareInfoRequest{ShareID: shareID}).
SetResult(GetShareInfoResponse{}).
SetError(ErrorResponse{}).
Post(V2ShareLinkGetShareByAnonymous)
Expand All @@ -18,11 +18,11 @@ func (ali AliYunDrive) GetAnonymousShare(shareId string) (*GetShareInfoResponse,
return response, nil
}

func (ali AliYunDrive) GetShare(shareId string, shareToken string) (data chan *BaseShareFile, err error) {
func (ali AliYunDrive) GetShare(shareID string, shareToken string) (data chan *BaseShareFile, err error) {
result := make(chan *BaseShareFile, 100)

go func() {
err = ali.fileList(shareToken, shareId, result)
err = ali.fileList(shareToken, shareID, result)
if err != nil {
log.Fatal(err)
}
Expand All @@ -31,10 +31,10 @@ func (ali AliYunDrive) GetShare(shareId string, shareToken string) (data chan *B
return result, nil
}

func (ali AliYunDrive) GetShredToken(shareId string, sharePwd string) (*GetShareTokenResponse, error) {
func (ali AliYunDrive) GetShredToken(shareID string, sharePwd string) (*GetShareTokenResponse, error) {
downloadResp, err := ali.Client.R().
SetAuthToken(ali.GetAuthorizationToken()).
SetBody(GetShareTokenRequest{ShareId: shareId, SharePwd: sharePwd}).
SetBody(GetShareTokenRequest{ShareID: shareID, SharePwd: sharePwd}).
SetResult(GetShareTokenResponse{}).
SetError(ErrorResponse{}).
Post(V2ShareLinkGetShareToken)
Expand All @@ -45,11 +45,11 @@ func (ali AliYunDrive) GetShredToken(shareId string, sharePwd string) (*GetShare
return response, nil
}

func (ali AliYunDrive) fileList(shareToken string, shareId string, result chan *BaseShareFile) error {
func (ali AliYunDrive) fileList(shareToken string, shareID string, result chan *BaseShareFile) error {
return ali.fileListByMarker(FileListParam{
shareToken: shareToken,
shareId: shareId,
parentFileId: "root",
shareID: shareID,
parentFileID: "root",
marker: "",
}, result)
}
Expand All @@ -59,9 +59,9 @@ func (ali AliYunDrive) fileListByMarker(param FileListParam, result chan *BaseSh
SetAuthToken(ali.GetAuthorizationToken()).
SetHeader(xShareToken, param.shareToken).
SetBody(GetShareFileListRequest{
ShareId: param.shareId,
ParentFileId: param.parentFileId,
UrlExpireSec: 14400,
ShareID: param.shareID,
ParentFileID: param.parentFileID,
URLExpireSec: 14400,
OrderBy: "name",
OrderDirection: "DESC",
Limit: 20,
Expand All @@ -78,8 +78,8 @@ func (ali AliYunDrive) fileListByMarker(param FileListParam, result chan *BaseSh
if item.FileType == "folder" {
err := ali.fileListByMarker(FileListParam{
shareToken: param.shareToken,
shareId: param.shareId,
parentFileId: item.FileId,
shareID: param.shareID,
parentFileID: item.FileID,
marker: "",
}, result)
if err != nil {
Expand All @@ -92,8 +92,8 @@ func (ali AliYunDrive) fileListByMarker(param FileListParam, result chan *BaseSh
if data.NextMarker != "" {
err := ali.fileListByMarker(FileListParam{
shareToken: param.shareToken,
shareId: param.shareId,
parentFileId: param.parentFileId,
shareID: param.shareID,
parentFileID: param.parentFileID,
marker: data.NextMarker,
}, result)
if err != nil {
Expand All @@ -103,21 +103,21 @@ func (ali AliYunDrive) fileListByMarker(param FileListParam, result chan *BaseSh
return nil
}

func (ali AliYunDrive) GetFileDownloadUrl(shareToken string, shareId string, fileId string) (string, error) {
func (ali AliYunDrive) GetFileDownloadURL(shareToken string, shareID string, fileID string) (string, error) {
downloadResp, err := ali.Client.R().
SetAuthToken(ali.GetAuthorizationToken()).
SetHeader(xShareToken, shareToken).
SetBody(GetShareLinkDownloadUrlRequest{
ShareId: shareId,
FileId: fileId,
SetBody(GetShareLinkDownloadURLRequest{
ShareID: shareID,
FileID: fileID,
ExpireSec: 600,
}).
SetResult(GetShareLinkDownloadUrlResponse{}).
SetResult(GetShareLinkDownloadURLResponse{}).
SetError(ErrorResponse{}).
Post(V2FileGetShareLinkDownloadUrl)
Post(V2FileGetShareLinkDownloadURL)
if err != nil {
return "", err
}
i := downloadResp.Result().(*GetShareLinkDownloadUrlResponse)
return i.DownloadUrl, nil
i := downloadResp.Result().(*GetShareLinkDownloadURLResponse)
return i.DownloadURL, nil
}
Loading

0 comments on commit 5e14247

Please sign in to comment.