From fefaa097934fa8e833f626f66d0fdc0b73ed1fa8 Mon Sep 17 00:00:00 2001 From: what Date: Fri, 22 Nov 2024 15:43:05 +0800 Subject: [PATCH] [feat] PkgVersion --- base/pkg_version.go | 34 ++++++++++++++++++++++++++++++++-- errno.go | 7 ++++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/base/pkg_version.go b/base/pkg_version.go index bd47c3f..5f439bf 100644 --- a/base/pkg_version.go +++ b/base/pkg_version.go @@ -7,10 +7,40 @@ type PkgVersion struct { FileName string `db:"filename"` SourceMapFileName string `db:"sourcemapFileName"` Imports []string `db:"imports"` - VersionAt string `db:"version_at"` + Platform string `db:"platform"` + ReleaseAt string `db:"release_at"` + UpdatedAt string `db:"updated_at"` + CreatedAt string `db:"created_at"` } func (this PkgVersion) GetFile() []byte func (this PkgVersion) GetSourceMap() []byte -type GetPkgVersion func(pkg string) (PkgVersion, bool) +type GetPkgVersion func(pkg string, opts ...PkgOption) (PkgVersion, bool) + +// 筛选选项 +type PkgOption func(option *PkgOptions) +type PkgOptions struct { + platform string + hash string +} + +func (this PkgOptions) Platform() string { + return this.platform +} + +func (this PkgOptions) Hash() string { + return this.hash +} + +func PkgPlatform(value string) PkgOption { + return func(option *PkgOptions) { + option.platform = value + } +} + +func PkgHash(value string) PkgOption { + return func(option *PkgOptions) { + option.hash = value + } +} diff --git a/errno.go b/errno.go index 77c6c7b..b26cfa0 100644 --- a/errno.go +++ b/errno.go @@ -116,9 +116,10 @@ var ( ErrPkgInvalid = &Errno{Code: 20702, Msg: "pkg invalid"} ErrPkgPlatformInvalid = &Errno{Code: 20703, Msg: "pkg platform invalid"} ErrPkgUpgrade = &Errno{Code: 20704, Msg: "pkg upgrade fail"} - ErrPkgDownload = &Errno{Code: 20705, Msg: "pkg download fail"} - ErrPkgUpload = &Errno{Code: 20706, Msg: "pkg upload fail"} - ErrPkgBuild = &Errno{Code: 20707, Msg: "pkg build fail"} + ErrPkgRollback = &Errno{Code: 20705, Msg: "pkg version rollback fail"} + ErrPkgDownload = &Errno{Code: 20706, Msg: "pkg download fail"} + ErrPkgUpload = &Errno{Code: 20707, Msg: "pkg upload fail"} + ErrPkgBuild = &Errno{Code: 20708, Msg: "pkg build fail"} ) // 使用 错误码 和 error 创建新的 错误