diff options
Diffstat (limited to 'internal/db')
38 files changed, 99 insertions, 99 deletions
diff --git a/internal/db/access_tokens_test.go b/internal/db/access_tokens_test.go index 2c915ab8..36a39c73 100644 --- a/internal/db/access_tokens_test.go +++ b/internal/db/access_tokens_test.go @@ -98,7 +98,7 @@ func TestAccessTokens(t *testing.T) { } t.Parallel() - tables := []interface{}{new(AccessToken)} + tables := []any{new(AccessToken)} db := &accessTokens{ DB: dbtest.NewDB(t, "accessTokens", tables...), } diff --git a/internal/db/actions_test.go b/internal/db/actions_test.go index cc64850e..aa6bbf4e 100644 --- a/internal/db/actions_test.go +++ b/internal/db/actions_test.go @@ -99,7 +99,7 @@ func TestActions(t *testing.T) { } t.Parallel() - tables := []interface{}{new(Action), new(User), new(Repository), new(EmailAddress), new(Watch)} + tables := []any{new(Action), new(User), new(Repository), new(EmailAddress), new(Watch)} db := &actions{ DB: dbtest.NewDB(t, "actions", tables...), } diff --git a/internal/db/attachment.go b/internal/db/attachment.go index 75d92746..53372468 100644 --- a/internal/db/attachment.go +++ b/internal/db/attachment.go @@ -87,7 +87,7 @@ func NewAttachment(name string, buf []byte, file multipart.File) (_ *Attachment, var _ errutil.NotFound = (*ErrAttachmentNotExist)(nil) type ErrAttachmentNotExist struct { - args map[string]interface{} + args map[string]any } func IsErrAttachmentNotExist(err error) bool { @@ -109,7 +109,7 @@ func getAttachmentByUUID(e Engine, uuid string) (*Attachment, error) { if err != nil { return nil, err } else if !has { - return nil, ErrAttachmentNotExist{args: map[string]interface{}{"uuid": uuid}} + return nil, ErrAttachmentNotExist{args: map[string]any{"uuid": uuid}} } return attach, nil } diff --git a/internal/db/backup.go b/internal/db/backup.go index 76ea1fee..7c514519 100644 --- a/internal/db/backup.go +++ b/internal/db/backup.go @@ -26,7 +26,7 @@ import ( // getTableType returns the type name of a table definition without package name, // e.g. *db.LFSObject -> LFSObject. -func getTableType(t interface{}) string { +func getTableType(t any) string { return strings.TrimPrefix(fmt.Sprintf("%T", t), "*db.") } @@ -72,7 +72,7 @@ func DumpDatabase(ctx context.Context, db *gorm.DB, dirPath string, verbose bool return nil } -func dumpTable(ctx context.Context, db *gorm.DB, table interface{}, w io.Writer) error { +func dumpTable(ctx context.Context, db *gorm.DB, table any, w io.Writer) error { query := db.WithContext(ctx).Model(table) switch table.(type) { case *LFSObject: @@ -128,7 +128,7 @@ func dumpLegacyTables(ctx context.Context, dirPath string, verbose bool) error { return fmt.Errorf("create JSON file: %v", err) } - if err = x.Context(ctx).Asc("id").Iterate(table, func(idx int, bean interface{}) (err error) { + if err = x.Context(ctx).Asc("id").Iterate(table, func(idx int, bean any) (err error) { return jsoniter.NewEncoder(f).Encode(bean) }); err != nil { _ = f.Close() @@ -181,7 +181,7 @@ func ImportDatabase(ctx context.Context, db *gorm.DB, dirPath string, verbose bo return nil } -func importTable(ctx context.Context, db *gorm.DB, table interface{}, r io.Reader) error { +func importTable(ctx context.Context, db *gorm.DB, table any, r io.Reader) error { err := db.WithContext(ctx).Migrator().DropTable(table) if err != nil { return errors.Wrap(err, "drop table") diff --git a/internal/db/backup_test.go b/internal/db/backup_test.go index 52ce9aaa..fc00ada8 100644 --- a/internal/db/backup_test.go +++ b/internal/db/backup_test.go @@ -45,7 +45,7 @@ func TestDumpAndImport(t *testing.T) { } func setupDBToDump(t *testing.T, db *gorm.DB) { - vals := []interface{}{ + vals := []any{ &Access{ ID: 1, UserID: 1, diff --git a/internal/db/comment.go b/internal/db/comment.go index c5caa69d..cdfc1695 100644 --- a/internal/db/comment.go +++ b/internal/db/comment.go @@ -395,7 +395,7 @@ func CreateRefComment(doer *User, repo *Repository, issue *Issue, content, commi var _ errutil.NotFound = (*ErrCommentNotExist)(nil) type ErrCommentNotExist struct { - args map[string]interface{} + args map[string]any } func IsErrCommentNotExist(err error) bool { @@ -418,7 +418,7 @@ func GetCommentByID(id int64) (*Comment, error) { if err != nil { return nil, err } else if !has { - return nil, ErrCommentNotExist{args: map[string]interface{}{"commentID": id}} + return nil, ErrCommentNotExist{args: map[string]any{"commentID": id}} } return c, c.LoadAttributes() } diff --git a/internal/db/db.go b/internal/db/db.go index 600bdaf0..7b063dec 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -40,7 +40,7 @@ func newLogWriter() (logger.Writer, error) { // Tables is the list of struct-to-table mappings. // // NOTE: Lines are sorted in alphabetical order, each letter in its own line. -var Tables = []interface{}{ +var Tables = []any{ new(Access), new(AccessToken), new(Action), new(Follow), new(LFSObject), new(LoginSource), diff --git a/internal/db/email_addresses_test.go b/internal/db/email_addresses_test.go index f55db549..523f5fc5 100644 --- a/internal/db/email_addresses_test.go +++ b/internal/db/email_addresses_test.go @@ -21,7 +21,7 @@ func TestEmailAddresses(t *testing.T) { } t.Parallel() - tables := []interface{}{new(EmailAddress)} + tables := []any{new(EmailAddress)} db := &emailAddresses{ DB: dbtest.NewDB(t, "emailAddresses", tables...), } diff --git a/internal/db/follows_test.go b/internal/db/follows_test.go index 4caa447e..ce71fcaa 100644 --- a/internal/db/follows_test.go +++ b/internal/db/follows_test.go @@ -20,7 +20,7 @@ func TestFollows(t *testing.T) { } t.Parallel() - tables := []interface{}{new(User), new(EmailAddress), new(Follow)} + tables := []any{new(User), new(EmailAddress), new(Follow)} db := &follows{ DB: dbtest.NewDB(t, "follows", tables...), } diff --git a/internal/db/issue.go b/internal/db/issue.go index c7e09ab9..ea4518bc 100644 --- a/internal/db/issue.go +++ b/internal/db/issue.go @@ -793,7 +793,7 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string) var _ errutil.NotFound = (*ErrIssueNotExist)(nil) type ErrIssueNotExist struct { - args map[string]interface{} + args map[string]any } func IsErrIssueNotExist(err error) bool { @@ -813,12 +813,12 @@ func (ErrIssueNotExist) NotFound() bool { func GetIssueByRef(ref string) (*Issue, error) { n := strings.IndexByte(ref, byte('#')) if n == -1 { - return nil, ErrIssueNotExist{args: map[string]interface{}{"ref": ref}} + return nil, ErrIssueNotExist{args: map[string]any{"ref": ref}} } index := com.StrTo(ref[n+1:]).MustInt64() if index == 0 { - return nil, ErrIssueNotExist{args: map[string]interface{}{"ref": ref}} + return nil, ErrIssueNotExist{args: map[string]any{"ref": ref}} } repo, err := GetRepositoryByRef(ref[:n]) @@ -844,7 +844,7 @@ func GetRawIssueByIndex(repoID, index int64) (*Issue, error) { if err != nil { return nil, err } else if !has { - return nil, ErrIssueNotExist{args: map[string]interface{}{"repoID": repoID, "index": index}} + return nil, ErrIssueNotExist{args: map[string]any{"repoID": repoID, "index": index}} } return issue, nil } @@ -864,7 +864,7 @@ func getRawIssueByID(e Engine, id int64) (*Issue, error) { if err != nil { return nil, err } else if !has { - return nil, ErrIssueNotExist{args: map[string]interface{}{"issueID": id}} + return nil, ErrIssueNotExist{args: map[string]any{"issueID": id}} } return issue, nil } diff --git a/internal/db/issue_label.go b/internal/db/issue_label.go index f7fdf6a6..e5404880 100644 --- a/internal/db/issue_label.go +++ b/internal/db/issue_label.go @@ -107,7 +107,7 @@ func NewLabels(labels ...*Label) error { var _ errutil.NotFound = (*ErrLabelNotExist)(nil) type ErrLabelNotExist struct { - args map[string]interface{} + args map[string]any } func IsErrLabelNotExist(err error) bool { @@ -128,7 +128,7 @@ func (ErrLabelNotExist) NotFound() bool { // and can return arbitrary label with any valid ID. func getLabelOfRepoByName(e Engine, repoID int64, labelName string) (*Label, error) { if len(labelName) <= 0 { - return nil, ErrLabelNotExist{args: map[string]interface{}{"repoID": repoID}} + return nil, ErrLabelNotExist{args: map[string]any{"repoID": repoID}} } l := &Label{ @@ -139,7 +139,7 @@ func getLabelOfRepoByName(e Engine, repoID int64, labelName string) (*Label, err if err != nil { return nil, err } else if !has { - return nil, ErrLabelNotExist{args: map[string]interface{}{"repoID": repoID}} + return nil, ErrLabelNotExist{args: map[string]any{"repoID": repoID}} } return l, nil } @@ -149,7 +149,7 @@ func getLabelOfRepoByName(e Engine, repoID int64, labelName string) (*Label, err // and can return arbitrary label with any valid ID. func getLabelOfRepoByID(e Engine, repoID, labelID int64) (*Label, error) { if labelID <= 0 { - return nil, ErrLabelNotExist{args: map[string]interface{}{"repoID": repoID, "labelID": labelID}} + return nil, ErrLabelNotExist{args: map[string]any{"repoID": repoID, "labelID": labelID}} } l := &Label{ @@ -160,7 +160,7 @@ func getLabelOfRepoByID(e Engine, repoID, labelID int64) (*Label, error) { if err != nil { return nil, err } else if !has { - return nil, ErrLabelNotExist{args: map[string]interface{}{"repoID": repoID, "labelID": labelID}} + return nil, ErrLabelNotExist{args: map[string]any{"repoID": repoID, "labelID": labelID}} } return l, nil } diff --git a/internal/db/lfs_test.go b/internal/db/lfs_test.go index 690962e7..cf56e37d 100644 --- a/internal/db/lfs_test.go +++ b/internal/db/lfs_test.go @@ -23,7 +23,7 @@ func TestLFS(t *testing.T) { } t.Parallel() - tables := []interface{}{new(LFSObject)} + tables := []any{new(LFSObject)} db := &lfs{ DB: dbtest.NewDB(t, "lfs", tables...), } diff --git a/internal/db/login_source_files.go b/internal/db/login_source_files.go index 385b7402..494f828a 100644 --- a/internal/db/login_source_files.go +++ b/internal/db/login_source_files.go @@ -220,7 +220,7 @@ type loginSourceFileStore interface { // SetGeneral sets new value to the given key in the general (default) section. SetGeneral(name, value string) // SetConfig sets new values to the "config" section. - SetConfig(cfg interface{}) error + SetConfig(cfg any) error // Save persists values to file system. Save() error } @@ -236,7 +236,7 @@ func (f *loginSourceFile) SetGeneral(name, value string) { f.file.Section("").Key(name).SetValue(value) } -func (f *loginSourceFile) SetConfig(cfg interface{}) error { +func (f *loginSourceFile) SetConfig(cfg any) error { return f.file.Section("config").ReflectFrom(cfg) } diff --git a/internal/db/login_sources.go b/internal/db/login_sources.go index 1ce5caa2..8bbbaf07 100644 --- a/internal/db/login_sources.go +++ b/internal/db/login_sources.go @@ -194,7 +194,7 @@ type CreateLoginSourceOptions struct { Name string Activated bool Default bool - Config interface{} + Config any } type ErrLoginSourceAlreadyExist struct { @@ -297,7 +297,7 @@ func (db *loginSources) ResetNonDefault(ctx context.Context, dflt *LoginSource) err := db.WithContext(ctx). Model(new(LoginSource)). Where("id != ?", dflt.ID). - Updates(map[string]interface{}{"is_default": false}). + Updates(map[string]any{"is_default": false}). Error if err != nil { return err diff --git a/internal/db/login_sources_test.go b/internal/db/login_sources_test.go index af0da97b..13c17f79 100644 --- a/internal/db/login_sources_test.go +++ b/internal/db/login_sources_test.go @@ -163,7 +163,7 @@ func TestLoginSources(t *testing.T) { } t.Parallel() - tables := []interface{}{new(LoginSource), new(User)} + tables := []any{new(LoginSource), new(User)} db := &loginSources{ DB: dbtest.NewDB(t, "loginSources", tables...), } diff --git a/internal/db/main_test.go b/internal/db/main_test.go index 4f19da43..fbb98a7e 100644 --- a/internal/db/main_test.go +++ b/internal/db/main_test.go @@ -51,7 +51,7 @@ func TestMain(m *testing.M) { } // clearTables removes all rows from given tables. -func clearTables(t *testing.T, db *gorm.DB, tables ...interface{}) error { +func clearTables(t *testing.T, db *gorm.DB, tables ...any) error { if t.Failed() { return nil } diff --git a/internal/db/milestone.go b/internal/db/milestone.go index 0d005205..0166a2da 100644 --- a/internal/db/milestone.go +++ b/internal/db/milestone.go @@ -134,7 +134,7 @@ func NewMilestone(m *Milestone) (err error) { var _ errutil.NotFound = (*ErrMilestoneNotExist)(nil) type ErrMilestoneNotExist struct { - args map[string]interface{} + args map[string]any } func IsErrMilestoneNotExist(err error) bool { @@ -159,7 +159,7 @@ func getMilestoneByRepoID(e Engine, repoID, id int64) (*Milestone, error) { if err != nil { return nil, err } else if !has { - return nil, ErrMilestoneNotExist{args: map[string]interface{}{"repoID": repoID, "milestoneID": id}} + return nil, ErrMilestoneNotExist{args: map[string]any{"repoID": repoID, "milestoneID": id}} } return m, nil } diff --git a/internal/db/mirror.go b/internal/db/mirror.go index 7006a063..21d86f47 100644 --- a/internal/db/mirror.go +++ b/internal/db/mirror.go @@ -298,7 +298,7 @@ func MirrorUpdate() { log.Trace("Doing: MirrorUpdate") - if err := x.Where("next_update_unix<=?", time.Now().Unix()).Iterate(new(Mirror), func(idx int, bean interface{}) error { + if err := x.Where("next_update_unix<=?", time.Now().Unix()).Iterate(new(Mirror), func(idx int, bean any) error { m := bean.(*Mirror) if m.Repo == nil { log.Error("Disconnected mirror repository found: %d", m.ID) diff --git a/internal/db/models.go b/internal/db/models.go index 88cdedae..76a11fb4 100644 --- a/internal/db/models.go +++ b/internal/db/models.go @@ -28,23 +28,23 @@ import ( // Engine represents a XORM engine or session. type Engine interface { - Delete(interface{}) (int64, error) - Exec(...interface{}) (sql.Result, error) - Find(interface{}, ...interface{}) error - Get(interface{}) (bool, error) - ID(interface{}) *xorm.Session - In(string, ...interface{}) *xorm.Session - Insert(...interface{}) (int64, error) - InsertOne(interface{}) (int64, error) - Iterate(interface{}, xorm.IterFunc) error - Sql(string, ...interface{}) *xorm.Session - Table(interface{}) *xorm.Session - Where(interface{}, ...interface{}) *xorm.Session + Delete(any) (int64, error) + Exec(...any) (sql.Result, error) + Find(any, ...any) error + Get(any) (bool, error) + ID(any) *xorm.Session + In(string, ...any) *xorm.Session + Insert(...any) (int64, error) + InsertOne(any) (int64, error) + Iterate(any, xorm.IterFunc) error + Sql(string, ...any) *xorm.Session + Table(any) *xorm.Session + Where(any, ...any) *xorm.Session } var ( x *xorm.Engine - legacyTables []interface{} + legacyTables []any HasEngine bool ) diff --git a/internal/db/org_team.go b/internal/db/org_team.go index c44deb67..d737167e 100644 --- a/internal/db/org_team.go +++ b/internal/db/org_team.go @@ -304,7 +304,7 @@ func NewTeam(t *Team) error { var _ errutil.NotFound = (*ErrTeamNotExist)(nil) type ErrTeamNotExist struct { - args map[string]interface{} + args map[string]any } func IsErrTeamNotExist(err error) bool { @@ -329,7 +329,7 @@ func getTeamOfOrgByName(e Engine, orgID int64, name string) (*Team, error) { if err != nil { return nil, err } else if !has { - return nil, ErrTeamNotExist{args: map[string]interface{}{"orgID": orgID, "name": name}} + return nil, ErrTeamNotExist{args: map[string]any{"orgID": orgID, "name": name}} } return t, nil } @@ -345,7 +345,7 @@ func getTeamByID(e Engine, teamID int64) (*Team, error) { if err != nil { return nil, err } else if !has { - return nil, ErrTeamNotExist{args: map[string]interface{}{"teamID": teamID}} + return nil, ErrTeamNotExist{args: map[string]any{"teamID": teamID}} } return t, nil } diff --git a/internal/db/org_users_test.go b/internal/db/org_users_test.go index ff7cd7b2..49f238d3 100644 --- a/internal/db/org_users_test.go +++ b/internal/db/org_users_test.go @@ -20,7 +20,7 @@ func TestOrgUsers(t *testing.T) { } t.Parallel() - tables := []interface{}{new(OrgUser)} + tables := []any{new(OrgUser)} db := &orgUsers{ DB: dbtest.NewDB(t, "orgUsers", tables...), } diff --git a/internal/db/orgs_test.go b/internal/db/orgs_test.go index 76e79345..623f43f8 100644 --- a/internal/db/orgs_test.go +++ b/internal/db/orgs_test.go @@ -21,7 +21,7 @@ func TestOrgs(t *testing.T) { } t.Parallel() - tables := []interface{}{new(User), new(EmailAddress), new(OrgUser)} + tables := []any{new(User), new(EmailAddress), new(OrgUser)} db := &orgs{ DB: dbtest.NewDB(t, "orgs", tables...), } diff --git a/internal/db/perms_test.go b/internal/db/perms_test.go index 1e09f1d2..4d3c93c6 100644 --- a/internal/db/perms_test.go +++ b/internal/db/perms_test.go @@ -20,7 +20,7 @@ func TestPerms(t *testing.T) { } t.Parallel() - tables := []interface{}{new(Access)} + tables := []any{new(Access)} db := &perms{ DB: dbtest.NewDB(t, "perms", tables...), } diff --git a/internal/db/pull.go b/internal/db/pull.go index b0f723fa..09df38ea 100644 --- a/internal/db/pull.go +++ b/internal/db/pull.go @@ -526,7 +526,7 @@ func GetUnmergedPullRequest(headRepoID, baseRepoID int64, headBranch, baseBranch if err != nil { return nil, err } else if !has { - return nil, ErrPullRequestNotExist{args: map[string]interface{}{ + return nil, ErrPullRequestNotExist{args: map[string]any{ "headRepoID": headRepoID, "baseRepoID": baseRepoID, "headBranch": headBranch, @@ -558,7 +558,7 @@ func GetUnmergedPullRequestsByBaseInfo(repoID int64, branch string) ([]*PullRequ var _ errutil.NotFound = (*ErrPullRequestNotExist)(nil) type ErrPullRequestNotExist struct { - args map[string]interface{} + args map[string]any } func IsErrPullRequestNotExist(err error) bool { @@ -580,7 +580,7 @@ func getPullRequestByID(e Engine, id int64) (*PullRequest, error) { if err != nil { return nil, err } else if !has { - return nil, ErrPullRequestNotExist{args: map[string]interface{}{"pullRequestID": id}} + return nil, ErrPullRequestNotExist{args: map[string]any{"pullRequestID": id}} } return pr, pr.loadAttributes(e) } @@ -598,7 +598,7 @@ func getPullRequestByIssueID(e Engine, issueID int64) (*PullRequest, error) { if err != nil { return nil, err } else if !has { - return nil, ErrPullRequestNotExist{args: map[string]interface{}{"issueID": issueID}} + return nil, ErrPullRequestNotExist{args: map[string]any{"issueID": issueID}} } return pr, pr.loadAttributes(e) } @@ -845,7 +845,7 @@ func TestPullRequests() { _ = x.Iterate(PullRequest{ Status: PULL_REQUEST_STATUS_CHECKING, }, - func(idx int, bean interface{}) error { + func(idx int, bean any) error { pr := bean.(*PullRequest) if err := pr.LoadAttributes(); err != nil { diff --git a/internal/db/release.go b/internal/db/release.go index 43f90d38..26b7595d 100644 --- a/internal/db/release.go +++ b/internal/db/release.go @@ -209,7 +209,7 @@ func NewRelease(gitRepo *git.Repository, r *Release, uuids []string) error { var _ errutil.NotFound = (*ErrReleaseNotExist)(nil) type ErrReleaseNotExist struct { - args map[string]interface{} + args map[string]any } func IsErrReleaseNotExist(err error) bool { @@ -231,7 +231,7 @@ func GetRelease(repoID int64, tagName string) (*Release, error) { if err != nil { return nil, err } else if !isExist { - return nil, ErrReleaseNotExist{args: map[string]interface{}{"tag": tagName}} + return nil, ErrReleaseNotExist{args: map[string]any{"tag": tagName}} } r := &Release{RepoID: repoID, LowerTagName: strings.ToLower(tagName)} @@ -249,7 +249,7 @@ func GetReleaseByID(id int64) (*Release, error) { if err != nil { return nil, err } else if !has { - return nil, ErrReleaseNotExist{args: map[string]interface{}{"releaseID": id}} + return nil, ErrReleaseNotExist{args: map[string]any{"releaseID": id}} } return r, r.LoadAttributes() diff --git a/internal/db/repo.go b/internal/db/repo.go index 4d1c3e82..27b61df2 100644 --- a/internal/db/repo.go +++ b/internal/db/repo.go @@ -1623,7 +1623,7 @@ func DeleteRepository(ownerID, repoID int64) error { if err != nil { return err } else if !has { - return ErrRepoNotExist{args: map[string]interface{}{"ownerID": ownerID, "repoID": repoID}} + return ErrRepoNotExist{args: map[string]any{"ownerID": ownerID, "repoID": repoID}} } // In case is a organization. @@ -1764,7 +1764,7 @@ func GetRepositoryByName(ownerID int64, name string) (*Repository, error) { if err != nil { return nil, err } else if !has { - return nil, ErrRepoNotExist{args: map[string]interface{}{"ownerID": ownerID, "name": name}} + return nil, ErrRepoNotExist{args: map[string]any{"ownerID": ownerID, "name": name}} } return repo, repo.LoadAttributes() } @@ -1775,7 +1775,7 @@ func getRepositoryByID(e Engine, id int64) (*Repository, error) { if err != nil { return nil, err } else if !has { - return nil, ErrRepoNotExist{args: map[string]interface{}{"repoID": id}} + return nil, ErrRepoNotExist{args: map[string]any{"repoID": id}} } return repo, repo.loadAttributes(e) } @@ -1909,7 +1909,7 @@ func DeleteOldRepositoryArchives() { formats := []string{"zip", "targz"} oldestTime := time.Now().Add(-conf.Cron.RepoArchiveCleanup.OlderThan) if err := x.Where("id > 0").Iterate(new(Repository), - func(idx int, bean interface{}) error { + func(idx int, bean any) error { repo := bean.(*Repository) basePath := filepath.Join(repo.RepoPath(), "archives") for _, format := range formats { @@ -1962,7 +1962,7 @@ func DeleteRepositoryArchives() error { defer taskStatusTable.Stop(_CLEAN_OLD_ARCHIVES) return x.Where("id > 0").Iterate(new(Repository), - func(idx int, bean interface{}) error { + func(idx int, bean any) error { repo := bean.(*Repository) return os.RemoveAll(filepath.Join(repo.RepoPath(), "archives")) }) @@ -1971,7 +1971,7 @@ func DeleteRepositoryArchives() error { func gatherMissingRepoRecords() ([]*Repository, error) { repos := make([]*Repository, 0, 10) if err := x.Where("id > 0").Iterate(new(Repository), - func(idx int, bean interface{}) error { + func(idx int, bean any) error { repo := bean.(*Repository) if !com.IsDir(repo.RepoPath()) { repos = append(repos, repo) @@ -2033,7 +2033,7 @@ func ReinitMissingRepositories() error { // to make sure the binary and custom conf path are up-to-date. func SyncRepositoryHooks() error { return x.Where("id > 0").Iterate(new(Repository), - func(idx int, bean interface{}) error { + func(idx int, bean any) error { repo := bean.(*Repository) if err := createDelegateHooks(repo.RepoPath()); err != nil { return err @@ -2067,7 +2067,7 @@ func GitFsck() { log.Trace("Doing: GitFsck") if err := x.Where("id>0").Iterate(new(Repository), - func(idx int, bean interface{}) error { + func(idx int, bean any) error { repo := bean.(*Repository) repoPath := repo.RepoPath() err := git.Fsck(repoPath, git.FsckOptions{ @@ -2092,7 +2092,7 @@ func GitFsck() { func GitGcRepos() error { args := append([]string{"gc"}, conf.Git.GCArgs...) return x.Where("id > 0").Iterate(new(Repository), - func(idx int, bean interface{}) error { + func(idx int, bean any) error { repo := bean.(*Repository) if err := repo.GetOwner(); err != nil { return err diff --git a/internal/db/repo_branch.go b/internal/db/repo_branch.go index dc9e8795..65bcdc4a 100644 --- a/internal/db/repo_branch.go +++ b/internal/db/repo_branch.go @@ -48,7 +48,7 @@ func GetBranchesByPath(path string) ([]*Branch, error) { var _ errutil.NotFound = (*ErrBranchNotExist)(nil) type ErrBranchNotExist struct { - args map[string]interface{} + args map[string]any } func IsErrBranchNotExist(err error) bool { @@ -66,7 +66,7 @@ func (ErrBranchNotExist) NotFound() bool { func (repo *Repository) GetBranch(name string) (*Branch, error) { if !git.RepoHasBranch(repo.RepoPath(), name) { - return nil, ErrBranchNotExist{args: map[string]interface{}{"name": name}} + return nil, ErrBranchNotExist{args: map[string]any{"name": name}} } return &Branch{ RepoPath: repo.RepoPath(), @@ -122,7 +122,7 @@ func GetProtectBranchOfRepoByName(repoID int64, name string) (*ProtectBranch, er if err != nil { return nil, err } else if !has { - return nil, ErrBranchNotExist{args: map[string]interface{}{"name": name}} + return nil, ErrBranchNotExist{args: map[string]any{"name": name}} } return protectBranch, nil } diff --git a/internal/db/repos.go b/internal/db/repos.go index c1480b16..7ca78ad8 100644 --- a/internal/db/repos.go +++ b/internal/db/repos.go @@ -213,7 +213,7 @@ func (db *repos) Touch(ctx context.Context, id int64) error { return db.WithContext(ctx). Model(new(Repository)). Where("id = ?", id). - Updates(map[string]interface{}{ + Updates(map[string]any{ "is_bare": false, "updated_unix": db.NowFunc().Unix(), }). diff --git a/internal/db/repos_test.go b/internal/db/repos_test.go index ef832389..3c01105d 100644 --- a/internal/db/repos_test.go +++ b/internal/db/repos_test.go @@ -85,7 +85,7 @@ func TestRepos(t *testing.T) { } t.Parallel() - tables := []interface{}{new(Repository)} + tables := []any{new(Repository)} db := &repos{ DB: dbtest.NewDB(t, "repos", tables...), } diff --git a/internal/db/schemadoc/main.go b/internal/db/schemadoc/main.go index a46c86b0..664a2969 100644 --- a/internal/db/schemadoc/main.go +++ b/internal/db/schemadoc/main.go @@ -135,7 +135,7 @@ func generate(dialector gorm.Dialector) ([]*tableInfo, error) { } m := conn.Migrator().(interface { - RunWithValue(value interface{}, fc func(*gorm.Statement) error) error + RunWithValue(value any, fc func(*gorm.Statement) error) error FullDataTypeOf(*schema.Field) clause.Expr }) tableInfos := make([]*tableInfo, 0, len(db.Tables)) diff --git a/internal/db/ssh_key.go b/internal/db/ssh_key.go index 4bf5b73e..3cddab97 100644 --- a/internal/db/ssh_key.go +++ b/internal/db/ssh_key.go @@ -533,7 +533,7 @@ func RewriteAuthorizedKeys() error { } defer os.Remove(tmpPath) - err = x.Iterate(new(PublicKey), func(idx int, bean interface{}) (err error) { + err = x.Iterate(new(PublicKey), func(idx int, bean any) (err error) { _, err = f.WriteString((bean.(*PublicKey)).AuthorizedString()) return err }) @@ -688,7 +688,7 @@ func AddDeployKey(repoID int64, name, content string) (*DeployKey, error) { var _ errutil.NotFound = (*ErrDeployKeyNotExist)(nil) type ErrDeployKeyNotExist struct { - args map[string]interface{} + args map[string]any } func IsErrDeployKeyNotExist(err error) bool { @@ -711,7 +711,7 @@ func GetDeployKeyByID(id int64) (*DeployKey, error) { if err != nil { return nil, err } else if !has { - return nil, ErrDeployKeyNotExist{args: map[string]interface{}{"deployKeyID": id}} + return nil, ErrDeployKeyNotExist{args: map[string]any{"deployKeyID": id}} } return key, nil } @@ -726,7 +726,7 @@ func GetDeployKeyByRepo(keyID, repoID int64) (*DeployKey, error) { if err != nil { return nil, err } else if !has { - return nil, ErrDeployKeyNotExist{args: map[string]interface{}{"keyID": keyID, "repoID": repoID}} + return nil, ErrDeployKeyNotExist{args: map[string]any{"keyID": keyID, "repoID": repoID}} } return key, nil } diff --git a/internal/db/two_factors_test.go b/internal/db/two_factors_test.go index e2d58cd5..64e253bd 100644 --- a/internal/db/two_factors_test.go +++ b/internal/db/two_factors_test.go @@ -67,7 +67,7 @@ func TestTwoFactors(t *testing.T) { } t.Parallel() - tables := []interface{}{new(TwoFactor), new(TwoFactorRecoveryCode)} + tables := []any{new(TwoFactor), new(TwoFactorRecoveryCode)} db := &twoFactors{ DB: dbtest.NewDB(t, "twoFactors", tables...), } diff --git a/internal/db/user.go b/internal/db/user.go index 50b59630..9f4bdc97 100644 --- a/internal/db/user.go +++ b/internal/db/user.go @@ -39,7 +39,7 @@ func (u *User) AfterSet(colName string, _ xorm.Cell) { } // deleteBeans deletes all given beans, beans should contain delete conditions. -func deleteBeans(e Engine, beans ...interface{}) (err error) { +func deleteBeans(e Engine, beans ...any) (err error) { for i := range beans { if _, err = e.Delete(beans[i]); err != nil { return err @@ -208,7 +208,7 @@ func getUserByID(e Engine, id int64) (*User, error) { if err != nil { return nil, err } else if !has { - return nil, ErrUserNotExist{args: map[string]interface{}{"userID": id}} + return nil, ErrUserNotExist{args: map[string]any{"userID": id}} } return u, nil } diff --git a/internal/db/user_mail.go b/internal/db/user_mail.go index d657faa0..01ab4c5b 100644 --- a/internal/db/user_mail.go +++ b/internal/db/user_mail.go @@ -166,7 +166,7 @@ func MakeEmailPrimary(userID int64, email *EmailAddress) error { if err != nil { return err } else if !has { - return ErrUserNotExist{args: map[string]interface{}{"userID": email.UserID}} + return ErrUserNotExist{args: map[string]any{"userID": email.UserID}} } // Make sure the former primary email doesn't disappear. diff --git a/internal/db/users.go b/internal/db/users.go index 80b124ea..6e657ecb 100644 --- a/internal/db/users.go +++ b/internal/db/users.go @@ -158,7 +158,7 @@ func (db *users) Authenticate(ctx context.Context, login, password string, login return user, nil } - return nil, auth.ErrBadCredentials{Args: map[string]interface{}{"login": login, "userID": user.ID}} + return nil, auth.ErrBadCredentials{Args: map[string]any{"login": login, "userID": user.ID}} } authSourceID = user.LoginSource @@ -166,7 +166,7 @@ func (db *users) Authenticate(ctx context.Context, login, password string, login } else { // Non-local login source is always greater than 0. if loginSourceID <= 0 { - return nil, auth.ErrBadCredentials{Args: map[string]interface{}{"login": login}} + return nil, auth.ErrBadCredentials{Args: map[string]any{"login": login}} } authSourceID = loginSourceID @@ -406,7 +406,7 @@ func (db *users) DeleteCustomAvatar(ctx context.Context, userID int64) error { return db.WithContext(ctx). Model(&User{}). Where("id = ?", userID). - Updates(map[string]interface{}{ + Updates(map[string]any{ "use_custom_avatar": false, "updated_unix": db.NowFunc().Unix(), }). @@ -693,7 +693,7 @@ func (db *users) UseCustomAvatar(ctx context.Context, userID int64, avatar []byt return db.WithContext(ctx). Model(&User{}). Where("id = ?", userID). - Updates(map[string]interface{}{ + Updates(map[string]any{ "use_custom_avatar": true, "updated_unix": db.NowFunc().Unix(), }). diff --git a/internal/db/users_test.go b/internal/db/users_test.go index 6a63c5aa..b13bf5be 100644 --- a/internal/db/users_test.go +++ b/internal/db/users_test.go @@ -82,7 +82,7 @@ func TestUsers(t *testing.T) { } t.Parallel() - tables := []interface{}{new(User), new(EmailAddress), new(Repository), new(Follow), new(PullRequest), new(PublicKey)} + tables := []any{new(User), new(EmailAddress), new(Repository), new(Follow), new(PullRequest), new(PublicKey)} db := &users{ DB: dbtest.NewDB(t, "users", tables...), } @@ -134,13 +134,13 @@ func usersAuthenticate(t *testing.T, db *users) { t.Run("user not found", func(t *testing.T) { _, err := db.Authenticate(ctx, "bob", password, -1) - wantErr := auth.ErrBadCredentials{Args: map[string]interface{}{"login": "bob"}} + wantErr := auth.ErrBadCredentials{Args: map[string]any{"login": "bob"}} assert.Equal(t, wantErr, err) }) t.Run("invalid password", func(t *testing.T) { _, err := db.Authenticate(ctx, alice.Name, "bad_password", -1) - wantErr := auth.ErrBadCredentials{Args: map[string]interface{}{"login": alice.Name, "userID": alice.ID}} + wantErr := auth.ErrBadCredentials{Args: map[string]any{"login": alice.Name, "userID": alice.ID}} assert.Equal(t, wantErr, err) }) @@ -159,7 +159,7 @@ func usersAuthenticate(t *testing.T, db *users) { t.Run("login source mismatch", func(t *testing.T) { _, err := db.Authenticate(ctx, alice.Email, password, 1) gotErr := fmt.Sprintf("%v", err) - wantErr := ErrLoginSourceMismatch{args: map[string]interface{}{"actual": 0, "expect": 1}}.Error() + wantErr := ErrLoginSourceMismatch{args: map[string]any{"actual": 0, "expect": 1}}.Error() assert.Equal(t, wantErr, gotErr) }) diff --git a/internal/db/watches_test.go b/internal/db/watches_test.go index 46267ccd..973f64d4 100644 --- a/internal/db/watches_test.go +++ b/internal/db/watches_test.go @@ -18,7 +18,7 @@ func TestWatches(t *testing.T) { } t.Parallel() - tables := []interface{}{new(Watch)} + tables := []any{new(Watch)} db := &watches{ DB: dbtest.NewDB(t, "watches", tables...), } diff --git a/internal/db/webhook.go b/internal/db/webhook.go index c26cb5b4..91079d8a 100644 --- a/internal/db/webhook.go +++ b/internal/db/webhook.go @@ -241,7 +241,7 @@ func CreateWebhook(w *Webhook) error { var _ errutil.NotFound = (*ErrWebhookNotExist)(nil) type ErrWebhookNotExist struct { - args map[string]interface{} + args map[string]any } func IsErrWebhookNotExist(err error) bool { @@ -264,7 +264,7 @@ func getWebhook(bean *Webhook) (*Webhook, error) { if err != nil { return nil, err } else if !has { - return nil, ErrWebhookNotExist{args: map[string]interface{}{"webhookID": bean.ID}} + return nil, ErrWebhookNotExist{args: map[string]any{"webhookID": bean.ID}} } return bean, nil } @@ -494,7 +494,7 @@ func (t *HookTask) AfterSet(colName string, _ xorm.Cell) { } } -func (t *HookTask) ToJSON(v interface{}) string { +func (t *HookTask) ToJSON(v any) string { p, err := jsoniter.Marshal(v) if err != nil { log.Error("Marshal [%d]: %v", t.ID, err) @@ -524,7 +524,7 @@ func createHookTask(e Engine, t *HookTask) error { var _ errutil.NotFound = (*ErrHookTaskNotExist)(nil) type ErrHookTaskNotExist struct { - args map[string]interface{} + args map[string]any } func IsHookTaskNotExist(err error) bool { @@ -550,7 +550,7 @@ func GetHookTaskOfWebhookByUUID(webhookID int64, uuid string) (*HookTask, error) if err != nil { return nil, err } else if !has { - return nil, ErrHookTaskNotExist{args: map[string]interface{}{"webhookID": webhookID, "uuid": uuid}} + return nil, ErrHookTaskNotExist{args: map[string]any{"webhookID": webhookID, "uuid": uuid}} } return hookTask, nil } @@ -788,7 +788,7 @@ func (t *HookTask) deliver() { func DeliverHooks() { tasks := make([]*HookTask, 0, 10) _ = x.Where("is_delivered = ?", false).Iterate(new(HookTask), - func(idx int, bean interface{}) error { + func(idx int, bean any) error { t := bean.(*HookTask) t.deliver() tasks = append(tasks, t) |