Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 760686f

Browse files
committed
记录 Go 安装包下载次数
1 parent 5955849 commit 760686f

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

config/db.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,7 @@ CREATE TABLE IF NOT EXISTS `download` (
799799
`is_recommend` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '是否推荐(推荐的高亮显示)',
800800
`category` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0-Archived versions; 1-Stable versions; 2-Unstable versions;',
801801
`seq` int unsigned NOT NULL DEFAULT 0 COMMENT '排序,越大越靠前',
802+
`times` int unsigned NOT NULl DEFAULT 0 COMMENT '下载次数',
802803
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
803804
PRIMARY KEY (`id`)
804805
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '下载信息表';

src/http/controller/download.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ var filenameReg = regexp.MustCompile(`\d+\.\d[a-z\.]*\d+`)
8484
func (self DownloadController) FetchGoInstallPackage(ctx echo.Context) error {
8585
filename := ctx.Param("filename")
8686

87+
go logic.DefaultDownload.RecordDLTimes(ctx, filename)
88+
8789
officalUrl := GoStoragePrefix + filename
8890
resp, err := self.headWithTimeout(officalUrl)
8991
if err == nil && resp.StatusCode == http.StatusOK {

src/logic/download.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ func (DownloadLogic) FindAll(ctx context.Context) []*model.Download {
2929

3030
return downloads
3131
}
32+
33+
func (DownloadLogic) RecordDLTimes(ctx context.Context, filename string) error {
34+
MasterDB.Where("filename=?", filename).Incr("times", 1).Update(new(model.Download))
35+
36+
return nil
37+
}

0 commit comments

Comments
 (0)