aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorsilverwind <me@silverwind.io>2023-07-04 20:36:08 +0200
committerGitHub <noreply@github.com>2023-07-04 18:36:08 +0000
commit88f835192d1a554d233b0ec4daa33276b7eb2910 (patch)
tree438140c295791e64a3b78dcfeae57701bcf296c3 /models
parent00dbba7f4266032a2b91b760e7c611950ffad096 (diff)
downloadgitea-88f835192d1a554d233b0ec4daa33276b7eb2910.tar.gz
gitea-88f835192d1a554d233b0ec4daa33276b7eb2910.zip
Replace `interface{}` with `any` (#25686)
Result of running `perl -p -i -e 's#interface\{\}#any#g' **/*` and `make fmt`. Basically the same [as golang did](https://github.com/golang/go/commit/2580d0e08d5e9f979b943758d3c49877fb2324cb).
Diffstat (limited to 'models')
-rw-r--r--models/admin/task.go2
-rw-r--r--models/asymkey/ssh_key_authorized_keys.go4
-rw-r--r--models/asymkey/ssh_key_authorized_principals.go2
-rw-r--r--models/db/context.go22
-rwxr-xr-xmodels/db/engine.go62
-rw-r--r--models/db/error.go2
-rw-r--r--models/db/log.go18
-rw-r--r--models/git/branch.go2
-rw-r--r--models/git/lfs.go2
-rw-r--r--models/issues/comment.go4
-rw-r--r--models/issues/issue.go6
-rw-r--r--models/issues/issue_update.go6
-rw-r--r--models/issues/review.go2
-rw-r--r--models/migrations/base/db.go4
-rw-r--r--models/migrations/base/tests.go2
-rw-r--r--models/migrations/v1_10/v100.go10
-rw-r--r--models/migrations/v1_16/v189.go6
-rw-r--r--models/migrations/v1_16/v189_test.go4
-rw-r--r--models/migrations/v1_19/v233_test.go2
-rw-r--r--models/migrations/v1_6/v70.go12
-rw-r--r--models/migrations/v1_8/v76.go10
-rw-r--r--models/packages/descriptor.go4
-rw-r--r--models/repo.go2
-rw-r--r--models/repo/mirror.go2
-rw-r--r--models/repo/pushmirror.go2
-rw-r--r--models/repo/pushmirror_test.go2
-rw-r--r--models/repo/release.go2
-rw-r--r--models/repo/repo_list.go2
-rw-r--r--models/system/notice.go4
-rw-r--r--models/unittest/consistency.go22
-rw-r--r--models/unittest/reflection.go2
-rw-r--r--models/unittest/testdb.go2
-rw-r--r--models/user/external_login_user.go10
-rw-r--r--models/webhook/hooktask.go2
34 files changed, 121 insertions, 121 deletions
diff --git a/models/admin/task.go b/models/admin/task.go
index fc40b13d02..8aa397ad35 100644
--- a/models/admin/task.go
+++ b/models/admin/task.go
@@ -44,7 +44,7 @@ func init() {
// TranslatableMessage represents JSON struct that can be translated with a Locale
type TranslatableMessage struct {
Format string
- Args []interface{} `json:"omitempty"`
+ Args []any `json:"omitempty"`
}
// LoadRepo loads repository of the task
diff --git a/models/asymkey/ssh_key_authorized_keys.go b/models/asymkey/ssh_key_authorized_keys.go
index e138182d68..77803d6709 100644
--- a/models/asymkey/ssh_key_authorized_keys.go
+++ b/models/asymkey/ssh_key_authorized_keys.go
@@ -47,7 +47,7 @@ var sshOpLocker sync.Mutex
// AuthorizedStringForKey creates the authorized keys string appropriate for the provided key
func AuthorizedStringForKey(key *PublicKey) string {
sb := &strings.Builder{}
- _ = setting.SSH.AuthorizedKeysCommandTemplateTemplate.Execute(sb, map[string]interface{}{
+ _ = setting.SSH.AuthorizedKeysCommandTemplateTemplate.Execute(sb, map[string]any{
"AppPath": util.ShellEscape(setting.AppPath),
"AppWorkPath": util.ShellEscape(setting.AppWorkPath),
"CustomConf": util.ShellEscape(setting.CustomConf),
@@ -175,7 +175,7 @@ func RewriteAllPublicKeys() error {
// RegeneratePublicKeys regenerates the authorized_keys file
func RegeneratePublicKeys(ctx context.Context, t io.StringWriter) error {
- if err := db.GetEngine(ctx).Where("type != ?", KeyTypePrincipal).Iterate(new(PublicKey), func(idx int, bean interface{}) (err error) {
+ if err := db.GetEngine(ctx).Where("type != ?", KeyTypePrincipal).Iterate(new(PublicKey), func(idx int, bean any) (err error) {
_, err = t.WriteString((bean.(*PublicKey)).AuthorizedString())
return err
}); err != nil {
diff --git a/models/asymkey/ssh_key_authorized_principals.go b/models/asymkey/ssh_key_authorized_principals.go
index 092839611f..592196c255 100644
--- a/models/asymkey/ssh_key_authorized_principals.go
+++ b/models/asymkey/ssh_key_authorized_principals.go
@@ -97,7 +97,7 @@ func RewriteAllPrincipalKeys(ctx context.Context) error {
}
func regeneratePrincipalKeys(ctx context.Context, t io.StringWriter) error {
- if err := db.GetEngine(ctx).Where("type = ?", KeyTypePrincipal).Iterate(new(PublicKey), func(idx int, bean interface{}) (err error) {
+ if err := db.GetEngine(ctx).Where("type = ?", KeyTypePrincipal).Iterate(new(PublicKey), func(idx int, bean any) (err error) {
_, err = t.WriteString((bean.(*PublicKey)).AuthorizedString())
return err
}); err != nil {
diff --git a/models/db/context.go b/models/db/context.go
index 59be1e1389..351aea8faf 100644
--- a/models/db/context.go
+++ b/models/db/context.go
@@ -52,7 +52,7 @@ func (ctx *Context) Engine() Engine {
}
// Value shadows Value for context.Context but allows us to get ourselves and an Engined object
-func (ctx *Context) Value(key interface{}) interface{} {
+func (ctx *Context) Value(key any) any {
if key == enginedContextKey {
return ctx
}
@@ -163,28 +163,28 @@ func txWithNoCheck(parentCtx context.Context, f func(ctx context.Context) error)
}
// Insert inserts records into database
-func Insert(ctx context.Context, beans ...interface{}) error {
+func Insert(ctx context.Context, beans ...any) error {
_, err := GetEngine(ctx).Insert(beans...)
return err
}
// Exec executes a sql with args
-func Exec(ctx context.Context, sqlAndArgs ...interface{}) (sql.Result, error) {
+func Exec(ctx context.Context, sqlAndArgs ...any) (sql.Result, error) {
return GetEngine(ctx).Exec(sqlAndArgs...)
}
// GetByBean filled empty fields of the bean according non-empty fields to query in database.
-func GetByBean(ctx context.Context, bean interface{}) (bool, error) {
+func GetByBean(ctx context.Context, bean any) (bool, error) {
return GetEngine(ctx).Get(bean)
}
// DeleteByBean deletes all records according non-empty fields of the bean as conditions.
-func DeleteByBean(ctx context.Context, bean interface{}) (int64, error) {
+func DeleteByBean(ctx context.Context, bean any) (int64, error) {
return GetEngine(ctx).Delete(bean)
}
// DeleteByID deletes the given bean with the given ID
-func DeleteByID(ctx context.Context, id int64, bean interface{}) (int64, error) {
+func DeleteByID(ctx context.Context, id int64, bean any) (int64, error) {
return GetEngine(ctx).ID(id).NoAutoTime().Delete(bean)
}
@@ -203,13 +203,13 @@ func FindIDs(ctx context.Context, tableName, idCol string, cond builder.Cond) ([
// DecrByIDs decreases the given column for entities of the "bean" type with one of the given ids by one
// Timestamps of the entities won't be updated
-func DecrByIDs(ctx context.Context, ids []int64, decrCol string, bean interface{}) error {
+func DecrByIDs(ctx context.Context, ids []int64, decrCol string, bean any) error {
_, err := GetEngine(ctx).Decr(decrCol).In("id", ids).NoAutoCondition().NoAutoTime().Update(bean)
return err
}
// DeleteBeans deletes all given beans, beans must contain delete conditions.
-func DeleteBeans(ctx context.Context, beans ...interface{}) (err error) {
+func DeleteBeans(ctx context.Context, beans ...any) (err error) {
e := GetEngine(ctx)
for i := range beans {
if _, err = e.Delete(beans[i]); err != nil {
@@ -220,7 +220,7 @@ func DeleteBeans(ctx context.Context, beans ...interface{}) (err error) {
}
// TruncateBeans deletes all given beans, beans may contain delete conditions.
-func TruncateBeans(ctx context.Context, beans ...interface{}) (err error) {
+func TruncateBeans(ctx context.Context, beans ...any) (err error) {
e := GetEngine(ctx)
for i := range beans {
if _, err = e.Truncate(beans[i]); err != nil {
@@ -231,12 +231,12 @@ func TruncateBeans(ctx context.Context, beans ...interface{}) (err error) {
}
// CountByBean counts the number of database records according non-empty fields of the bean as conditions.
-func CountByBean(ctx context.Context, bean interface{}) (int64, error) {
+func CountByBean(ctx context.Context, bean any) (int64, error) {
return GetEngine(ctx).Count(bean)
}
// TableName returns the table name according a bean object
-func TableName(bean interface{}) string {
+func TableName(bean any) string {
return x.TableName(bean)
}
diff --git a/models/db/engine.go b/models/db/engine.go
index 3eb16f8042..07e4d00270 100755
--- a/models/db/engine.go
+++ b/models/db/engine.go
@@ -25,7 +25,7 @@ import (
var (
x *xorm.Engine
- tables []interface{}
+ tables []any
initFuncs []func() error
// HasEngine specifies if we have a xorm.Engine
@@ -34,41 +34,41 @@ var (
// Engine represents a xorm engine or session.
type Engine interface {
- Table(tableNameOrBean interface{}) *xorm.Session
- Count(...interface{}) (int64, error)
- Decr(column string, arg ...interface{}) *xorm.Session
- Delete(...interface{}) (int64, error)
- Truncate(...interface{}) (int64, error)
- Exec(...interface{}) (sql.Result, error)
- Find(interface{}, ...interface{}) error
- Get(beans ...interface{}) (bool, error)
- ID(interface{}) *xorm.Session
- In(string, ...interface{}) *xorm.Session
- Incr(column string, arg ...interface{}) *xorm.Session
- Insert(...interface{}) (int64, error)
- Iterate(interface{}, xorm.IterFunc) error
- Join(joinOperator string, tablename, condition interface{}, args ...interface{}) *xorm.Session
- SQL(interface{}, ...interface{}) *xorm.Session
- Where(interface{}, ...interface{}) *xorm.Session
+ Table(tableNameOrBean any) *xorm.Session
+ Count(...any) (int64, error)
+ Decr(column string, arg ...any) *xorm.Session
+ Delete(...any) (int64, error)
+ Truncate(...any) (int64, error)
+ Exec(...any) (sql.Result, error)
+ Find(any, ...any) error
+ Get(beans ...any) (bool, error)
+ ID(any) *xorm.Session
+ In(string, ...any) *xorm.Session
+ Incr(column string, arg ...any) *xorm.Session
+ Insert(...any) (int64, error)
+ Iterate(any, xorm.IterFunc) error
+ Join(joinOperator string, tablename, condition any, args ...any) *xorm.Session
+ SQL(any, ...any) *xorm.Session
+ Where(any, ...any) *xorm.Session
Asc(colNames ...string) *xorm.Session
Desc(colNames ...string) *xorm.Session
Limit(limit int, start ...int) *xorm.Session
NoAutoTime() *xorm.Session
- SumInt(bean interface{}, columnName string) (res int64, err error)
- Sync2(...interface{}) error
+ SumInt(bean any, columnName string) (res int64, err error)
+ Sync2(...any) error
Select(string) *xorm.Session
- NotIn(string, ...interface{}) *xorm.Session
- OrderBy(interface{}, ...interface{}) *xorm.Session
- Exist(...interface{}) (bool, error)
+ NotIn(string, ...any) *xorm.Session
+ OrderBy(any, ...any) *xorm.Session
+ Exist(...any) (bool, error)
Distinct(...string) *xorm.Session
- Query(...interface{}) ([]map[string][]byte, error)
+ Query(...any) ([]map[string][]byte, error)
Cols(...string) *xorm.Session
Context(ctx context.Context) *xorm.Session
Ping() error
}
// TableInfo returns table's information via an object
-func TableInfo(v interface{}) (*schemas.Table, error) {
+func TableInfo(v any) (*schemas.Table, error) {
return x.TableInfo(v)
}
@@ -78,7 +78,7 @@ func DumpTables(tables []*schemas.Table, w io.Writer, tp ...schemas.DBType) erro
}
// RegisterModel registers model, if initfunc provided, it will be invoked after data model sync
-func RegisterModel(bean interface{}, initFunc ...func() error) {
+func RegisterModel(bean any, initFunc ...func() error) {
tables = append(tables, bean)
if len(initFuncs) > 0 && initFunc[0] != nil {
initFuncs = append(initFuncs, initFunc[0])
@@ -209,14 +209,14 @@ func InitEngineWithMigration(ctx context.Context, migrateFunc func(*xorm.Engine)
}
// NamesToBean return a list of beans or an error
-func NamesToBean(names ...string) ([]interface{}, error) {
- beans := []interface{}{}
+func NamesToBean(names ...string) ([]any, error) {
+ beans := []any{}
if len(names) == 0 {
beans = append(beans, tables...)
return beans, nil
}
// Need to map provided names to beans...
- beanMap := make(map[string]interface{})
+ beanMap := make(map[string]any)
for _, bean := range tables {
beanMap[strings.ToLower(reflect.Indirect(reflect.ValueOf(bean)).Type().Name())] = bean
@@ -224,7 +224,7 @@ func NamesToBean(names ...string) ([]interface{}, error) {
beanMap[strings.ToLower(x.TableName(bean, true))] = bean
}
- gotBean := make(map[interface{}]bool)
+ gotBean := make(map[any]bool)
for _, name := range names {
bean, ok := beanMap[strings.ToLower(strings.TrimSpace(name))]
if !ok {
@@ -266,7 +266,7 @@ func DumpDatabase(filePath, dbType string) error {
}
// MaxBatchInsertSize returns the table's max batch insert size
-func MaxBatchInsertSize(bean interface{}) int {
+func MaxBatchInsertSize(bean any) int {
t, err := x.TableInfo(bean)
if err != nil {
return 50
@@ -286,7 +286,7 @@ func DeleteAllRecords(tableName string) error {
}
// GetMaxID will return max id of the table
-func GetMaxID(beanOrTableName interface{}) (maxID int64, err error) {
+func GetMaxID(beanOrTableName any) (maxID int64, err error) {
_, err = x.Select("MAX(id)").Table(beanOrTableName).Get(&maxID)
return maxID, err
}
diff --git a/models/db/error.go b/models/db/error.go
index edc8e80a9c..665e970e17 100644
--- a/models/db/error.go
+++ b/models/db/error.go
@@ -25,7 +25,7 @@ func (err ErrCancelled) Error() string {
}
// ErrCancelledf returns an ErrCancelled for the provided format and args
-func ErrCancelledf(format string, args ...interface{}) error {
+func ErrCancelledf(format string, args ...any) error {
return ErrCancelled{
fmt.Sprintf(format, args...),
}
diff --git a/models/db/log.go b/models/db/log.go
index dd95f64ca8..307788ea2e 100644
--- a/models/db/log.go
+++ b/models/db/log.go
@@ -28,47 +28,47 @@ func NewXORMLogger(showSQL bool) xormlog.Logger {
const stackLevel = 8
// Log a message with defined skip and at logging level
-func (l *XORMLogBridge) Log(skip int, level log.Level, format string, v ...interface{}) {
+func (l *XORMLogBridge) Log(skip int, level log.Level, format string, v ...any) {
l.logger.Log(skip+1, level, format, v...)
}
// Debug show debug log
-func (l *XORMLogBridge) Debug(v ...interface{}) {
+func (l *XORMLogBridge) Debug(v ...any) {
l.Log(stackLevel, log.DEBUG, "%s", fmt.Sprint(v...))
}
// Debugf show debug log
-func (l *XORMLogBridge) Debugf(format string, v ...interface{}) {
+func (l *XORMLogBridge) Debugf(format string, v ...any) {
l.Log(stackLevel, log.DEBUG, format, v...)
}
// Error show error log
-func (l *XORMLogBridge) Error(v ...interface{}) {
+func (l *XORMLogBridge) Error(v ...any) {
l.Log(stackLevel, log.ERROR, "%s", fmt.Sprint(v...))
}
// Errorf show error log
-func (l *XORMLogBridge) Errorf(format string, v ...interface{}) {
+func (l *XORMLogBridge) Errorf(format string, v ...any) {
l.Log(stackLevel, log.ERROR, format, v...)
}
// Info show information level log
-func (l *XORMLogBridge) Info(v ...interface{}) {
+func (l *XORMLogBridge) Info(v ...any) {
l.Log(stackLevel, log.INFO, "%s", fmt.Sprint(v...))
}
// Infof show information level log
-func (l *XORMLogBridge) Infof(format string, v ...interface{}) {
+func (l *XORMLogBridge) Infof(format string, v ...any) {
l.Log(stackLevel, log.INFO, format, v...)
}
// Warn show warning log
-func (l *XORMLogBridge) Warn(v ...interface{}) {
+func (l *XORMLogBridge) Warn(v ...any) {
l.Log(stackLevel, log.WARN, "%s", fmt.Sprint(v...))
}
// Warnf show warnning log
-func (l *XORMLogBridge) Warnf(format string, v ...interface{}) {
+func (l *XORMLogBridge) Warnf(format string, v ...any) {
l.Log(stackLevel, log.WARN, format, v...)
}
diff --git a/models/git/branch.go b/models/git/branch.go
index 88ed858b19..5e99544958 100644
--- a/models/git/branch.go
+++ b/models/git/branch.go
@@ -355,7 +355,7 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, from, to str
// 4. Update all not merged pull request base branch name
_, err = sess.Table("pull_request").Where("base_repo_id=? AND base_branch=? AND has_merged=?",
repo.ID, from, false).
- Update(map[string]interface{}{"base_branch": to})
+ Update(map[string]any{"base_branch": to})
if err != nil {
return err
}
diff --git a/models/git/lfs.go b/models/git/lfs.go
index 0f90b29200..7d3da72a94 100644
--- a/models/git/lfs.go
+++ b/models/git/lfs.go
@@ -264,7 +264,7 @@ func LFSAutoAssociate(ctx context.Context, metas []*LFSMetaObject, user *user_mo
sess := db.GetEngine(ctx)
- oids := make([]interface{}, len(metas))
+ oids := make([]any, len(metas))
oidMap := make(map[string]*LFSMetaObject, len(metas))
for i, meta := range metas {
oids[i] = meta.Oid
diff --git a/models/issues/comment.go b/models/issues/comment.go
index dbe4434ca7..303c23916b 100644
--- a/models/issues/comment.go
+++ b/models/issues/comment.go
@@ -1131,7 +1131,7 @@ func DeleteComment(ctx context.Context, comment *Comment) error {
}
if _, err := e.Table("action").
Where("comment_id = ?", comment.ID).
- Update(map[string]interface{}{
+ Update(map[string]any{
"is_deleted": true,
}); err != nil {
return err
@@ -1156,7 +1156,7 @@ func UpdateCommentsMigrationsByType(tp structs.GitServiceType, originalAuthorID
}),
)).
And("comment.original_author_id = ?", originalAuthorID).
- Update(map[string]interface{}{
+ Update(map[string]any{
"poster_id": posterID,
"original_author": "",
"original_author_id": 0,
diff --git a/models/issues/issue.go b/models/issues/issue.go
index eab18f4892..364d53ba31 100644
--- a/models/issues/issue.go
+++ b/models/issues/issue.go
@@ -714,7 +714,7 @@ func (issue *Issue) Pin(ctx context.Context, user *user_model.User) error {
_, err = db.GetEngine(ctx).Table("issue").
Where("id = ?", issue.ID).
- Update(map[string]interface{}{
+ Update(map[string]any{
"pin_order": maxPin + 1,
})
if err != nil {
@@ -750,7 +750,7 @@ func (issue *Issue) Unpin(ctx context.Context, user *user_model.User) error {
_, err = db.GetEngine(ctx).Table("issue").
Where("id = ?", issue.ID).
- Update(map[string]interface{}{
+ Update(map[string]any{
"pin_order": 0,
})
if err != nil {
@@ -822,7 +822,7 @@ func (issue *Issue) MovePin(ctx context.Context, newPosition int) error {
_, err = db.GetEngine(dbctx).Table("issue").
Where("id = ?", issue.ID).
- Update(map[string]interface{}{
+ Update(map[string]any{
"pin_order": newPosition,
})
if err != nil {
diff --git a/models/issues/issue_update.go b/models/issues/issue_update.go
index b6fd720fe5..9453ddc085 100644
--- a/models/issues/issue_update.go
+++ b/models/issues/issue_update.go
@@ -511,7 +511,7 @@ func UpdateIssueDeadline(issue *Issue, deadlineUnix timeutil.TimeStamp, doer *us
}
// DeleteInIssue delete records in beans with external key issue_id = ?
-func DeleteInIssue(ctx context.Context, issueID int64, beans ...interface{}) error {
+func DeleteInIssue(ctx context.Context, issueID int64, beans ...any) error {
e := db.GetEngine(ctx)
for _, bean := range beans {
if _, err := e.In("issue_id", issueID).Delete(bean); err != nil {
@@ -673,7 +673,7 @@ func UpdateIssuesMigrationsByType(gitServiceType api.GitServiceType, originalAut
_, err := db.GetEngine(db.DefaultContext).Table("issue").
Where("repo_id IN (SELECT id FROM repository WHERE original_service_type = ?)", gitServiceType).
And("original_author_id = ?", originalAuthorID).
- Update(map[string]interface{}{
+ Update(map[string]any{
"poster_id": posterID,
"original_author": "",
"original_author_id": 0,
@@ -686,7 +686,7 @@ func UpdateReactionsMigrationsByType(gitServiceType api.GitServiceType, original
_, err := db.GetEngine(db.DefaultContext).Table("reaction").
Where("original_author_id = ?", originalAuthorID).
And(migratedIssueCond(gitServiceType)).
- Update(map[string]interface{}{
+ Update(map[string]any{
"user_id": userID,
"original_author": "",
"original_author_id": 0,
diff --git a/models/issues/review.go b/models/issues/review.go
index 3685c65ce5..dbacfa3a87 100644
--- a/models/issues/review.go
+++ b/models/issues/review.go
@@ -1111,7 +1111,7 @@ func UpdateReviewsMigrationsByType(tp structs.GitServiceType, originalAuthorID s
_, err := db.GetEngine(db.DefaultContext).Table("review").
Where("original_author_id = ?", originalAuthorID).
And(migratedIssueCond(tp)).
- Update(map[string]interface{}{
+ Update(map[string]any{
"reviewer_id": posterID,
"original_author": "",
"original_author_id": 0,
diff --git a/models/migrations/base/db.go b/models/migrations/base/db.go
index b038ad7337..51351cc7d3 100644
--- a/models/migrations/base/db.go
+++ b/models/migrations/base/db.go
@@ -27,7 +27,7 @@ import (
// RecreateTables will recreate the tables for the provided beans using the newly provided bean definition and move all data to that new table
// WARNING: YOU MUST PROVIDE THE FULL BEAN DEFINITION
-func RecreateTables(beans ...interface{}) func(*xorm.Engine) error {
+func RecreateTables(beans ...any) func(*xorm.Engine) error {
return func(x *xorm.Engine) error {
sess := x.NewSession()
defer sess.Close()
@@ -48,7 +48,7 @@ func RecreateTables(beans ...interface{}) func(*xorm.Engine) error {
// RecreateTable will recreate the table using the newly provided bean definition and move all data to that new table
// WARNING: YOU MUST PROVIDE THE FULL BEAN DEFINITION
// WARNING: YOU MUST COMMIT THE SESSION AT THE END
-func RecreateTable(sess *xorm.Session, bean interface{}) error {
+func RecreateTable(sess *xorm.Session, bean any) error {
// TODO: This will not work if there are foreign keys
tableName := sess.Engine().TableName(bean)
diff --git a/models/migrations/base/tests.go b/models/migrations/base/tests.go
index c3100ba665..e7ff524144 100644
--- a/models/migrations/base/tests.go
+++ b/models/migrations/base/tests.go
@@ -30,7 +30,7 @@ import (
// Provide models to be sync'd with the database - in particular any models you expect fixtures to be loaded from.
//
// fixtures in `models/migrations/fixtures/<TestName>` will be loaded automatically
-func PrepareTestEnv(t *testing.T, skip int, syncModels ...interface{}) (*xorm.Engine, func()) {
+func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (*xorm.Engine, func()) {
t.Helper()
ourSkip := 2
ourSkip += skip
diff --git a/models/migrations/v1_10/v100.go b/models/migrations/v1_10/v100.go
index bd11790b98..e94024f4df 100644
--- a/models/migrations/v1_10/v100.go
+++ b/models/migrations/v1_10/v100.go
@@ -59,11 +59,11 @@ func UpdateMigrationServiceTypes(x *xorm.Engine) error {
}
type ExternalLoginUser struct {
- ExternalID string `xorm:"pk NOT NULL"`
- UserID int64 `xorm:"INDEX NOT NULL"`
- LoginSourceID int64 `xorm:"pk NOT NULL"`
- RawData map[string]interface{} `xorm:"TEXT JSON"`
- Provider string `xorm:"index VARCHAR(25)"`
+ ExternalID string `xorm:"pk NOT NULL"`
+ UserID int64 `xorm:"INDEX NOT NULL"`
+ LoginSourceID int64 `xorm:"pk NOT NULL"`
+ RawData map[string]any `xorm:"TEXT JSON"`
+ Provider string `xorm:"index VARCHAR(25)"`
Email string
Name string
FirstName string
diff --git a/models/migrations/v1_16/v189.go b/models/migrations/v1_16/v189.go
index 32e3899a3a..79e3289ba7 100644
--- a/models/migrations/v1_16/v189.go
+++ b/models/migrations/v1_16/v189.go
@@ -14,7 +14,7 @@ import (
)
func UnwrapLDAPSourceCfg(x *xorm.Engine) error {
- jsonUnmarshalHandleDoubleEncode := func(bs []byte, v interface{}) error {
+ jsonUnmarshalHandleDoubleEncode := func(bs []byte, v any) error {
err := json.Unmarshal(bs, v)
if err != nil {
ok := true
@@ -54,7 +54,7 @@ func UnwrapLDAPSourceCfg(x *xorm.Engine) error {
const dldapType = 5
type WrappedSource struct {
- Source map[string]interface{}
+ Source map[string]any
}
// change lower_email as unique
@@ -77,7 +77,7 @@ func UnwrapLDAPSourceCfg(x *xorm.Engine) error {
for _, source := range sources {
wrapped := &WrappedSource{
- Source: map[string]interface{}{},
+ Source: map[string]any{},
}
err := jsonUnmarshalHandleDoubleEncode([]byte(source.Cfg), &wrapped)
if err != nil {
diff --git a/models/migrations/v1_16/v189_test.go b/models/migrations/v1_16/v189_test.go
index 96cb97c328..32ef821d27 100644
--- a/models/migrations/v1_16/v189_test.go
+++ b/models/migrations/v1_16/v189_test.go
@@ -62,8 +62,8 @@ func Test_UnwrapLDAPSourceCfg(t *testing.T) {
}
for _, source := range sources {
- converted := map[string]interface{}{}
- expected := map[string]interface{}{}
+ converted := map[string]any{}
+ expected := map[string]any{}
if err := json.Unmarshal([]byte(source.Cfg), &converted); err != nil {
assert.NoError(t, err)
diff --git a/models/migrations/v1_19/v233_test.go b/models/migrations/v1_19/v233_test.go
index 83558da334..32c10ab0f4 100644
--- a/models/migrations/v1_19/v233_test.go
+++ b/models/migrations/v1_19/v233_test.go
@@ -79,7 +79,7 @@ func Test_AddHeaderAuthorizationEncryptedColWebhook(t *testing.T) {
return
}
for _, h := range hookTasks {
- var m map[string]interface{}
+ var m map[string]any
err := json.Unmarshal([]byte(h.PayloadContent), &m)
assert.NoError(t, err)
assert.Nil(t, m["access_token"])
diff --git a/models/migrations/v1_6/v70.go b/models/migrations/v1_6/v70.go
index fec88266ba..74434a84a1 100644
--- a/models/migrations/v1_6/v70.go
+++ b/models/migrations/v1_6/v70.go
@@ -81,11 +81,11 @@ func AddIssueDependencies(x *xorm.Engine) (err error) {
// RepoUnit describes all units of a repository
type RepoUnit struct {
ID int64
- RepoID int64 `xorm:"INDEX(s)"`
- Type int `xorm:"INDEX(s)"`
- Config map[string]interface{} `xorm:"JSON"`
- CreatedUnix int64 `xorm:"INDEX CREATED"`
- Created time.Time `xorm:"-"`
+ RepoID int64 `xorm:"INDEX(s)"`
+ Type int `xorm:"INDEX(s)"`
+ Config map[string]any `xorm:"JSON"`
+ CreatedUnix int64 `xorm:"INDEX CREATED"`
+ Created time.Time `xorm:"-"`
}
// Updating existing issue units
@@ -96,7 +96,7 @@ func AddIssueDependencies(x *xorm.Engine) (err error) {
}
for _, unit := range units {
if unit.Config == nil {
- unit.Config = make(map[string]interface{})
+ unit.Config = make(map[string]any)
}
if _, ok := unit.Config["EnableDependencies"]; !ok {
unit.Config["EnableDependencies"] = setting.Service.DefaultEnableDependencies
diff --git a/models/migrations/v1_8/v76.go b/models/migrations/v1_8/v76.go
index f35856cc60..d3fbd94deb 100644
--- a/models/migrations/v1_8/v76.go
+++ b/models/migrations/v1_8/v76.go
@@ -15,10 +15,10 @@ func AddPullRequestRebaseWithMerge(x *xorm.Engine) error {
// RepoUnit describes all units of a repository
type RepoUnit struct {
ID int64
- RepoID int64 `xorm:"INDEX(s)"`
- Type int `xorm:"INDEX(s)"`
- Config map[string]interface{} `xorm:"JSON"`
- CreatedUnix timeutil.TimeStamp `xorm:"INDEX CREATED"`
+ RepoID int64 `xorm:"INDEX(s)"`
+ Type int `xorm:"INDEX(s)"`
+ Config map[string]any `xorm:"JSON"`
+ CreatedUnix timeutil.TimeStamp `xorm:"INDEX CREATED"`
}
const (
@@ -46,7 +46,7 @@ func AddPullRequestRebaseWithMerge(x *xorm.Engine) error {
}
for _, unit := range units {
if unit.Config == nil {
- unit.Config = make(map[string]interface{})
+ unit.Config = make(map[string]any)
}
// Allow the new merge style if all other merge styles are allowed
allowMergeRebase := true
diff --git a/models/packages/descriptor.go b/models/packages/descriptor.go
index ee35ffe0f2..f849ab5c04 100644
--- a/models/packages/descriptor.go
+++ b/models/packages/descriptor.go
@@ -59,7 +59,7 @@ type PackageDescriptor struct {
Creator *user_model.User
PackageProperties PackagePropertyList
VersionProperties PackagePropertyList
- Metadata interface{}
+ Metadata any
Files []*PackageFileDescriptor
}
@@ -136,7 +136,7 @@ func GetPackageDescriptor(ctx context.Context, pv *PackageVersion) (*PackageDesc
return nil, err
}
- var metadata interface{}
+ var metadata any
switch p.Type {
case TypeAlpine:
metadata = &alpine.VersionMetadata{}
diff --git a/models/repo.go b/models/repo.go
index 933f7e56a3..9044fc8aed 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -456,7 +456,7 @@ func repoStatsCorrectNumClosedPulls(ctx context.Context, id int64) error {
return repo_model.UpdateRepoIssueNumbers(ctx, id, true, true)
}
-func statsQuery(args ...interface{}) func(context.Context) ([]map[string][]byte, error) {
+func statsQuery(args ...any) func(context.Context) ([]map[string][]byte, error) {
return func(ctx context.Context) ([]map[string][]byte, error) {
return db.GetEngine(ctx).Query(args...)
}
diff --git a/models/repo/mirror.go b/models/repo/mirror.go
index c1d24a4886..39482037b2 100644
--- a/models/repo/mirror.go
+++ b/models/repo/mirror.go
@@ -105,7 +105,7 @@ func DeleteMirrorByRepoID(repoID int64) error {
}
// MirrorsIterate iterates all mirror repositories.
-func MirrorsIterate(limit int, f func(idx int, bean interface{}) error) error {
+func MirrorsIterate(limit int, f func(idx int, bean any) error) error {
sess := db.GetEngine(db.DefaultContext).
Where("next_update_unix<=?", time.Now().Unix()).
And("next_update_unix!=0").
diff --git a/models/repo/pushmirror.go b/models/repo/pushmirror.go
index 642020bb5e..f34484f638 100644
--- a/models/repo/pushmirror.go
+++ b/models/repo/pushmirror.go
@@ -127,7 +127,7 @@ func GetPushMirrorsSyncedOnCommit(ctx context.Context, repoID int64) ([]*PushMir
}
// PushMirrorsIterate iterates all push-mirror repositories.
-func PushMirrorsIterate(ctx context.Context, limit int, f func(idx int, bean interface{}) error) error {
+func PushMirrorsIterate(ctx context.Context, limit int, f func(idx int, bean any) error) error {
sess := db.GetEngine(ctx).
Where("last_update + (`interval` / ?) <= ?", time.Second, time.Now().Unix()).
And("`interval` != 0").
diff --git a/models/repo/pushmirror_test.go b/models/repo/pushmirror_test.go
index 2b3c5be292..9ab7023591 100644
--- a/models/repo/pushmirror_test.go
+++ b/models/repo/pushmirror_test.go
@@ -41,7 +41,7 @@ func TestPushMirrorsIterate(t *testing.T) {
time.Sleep(1 * time.Millisecond)
- repo_model.PushMirrorsIterate(db.DefaultContext, 1, func(idx int, bean interface{}) error {
+ repo_model.PushMirrorsIterate(db.DefaultContext, 1, func(idx int, bean any) error {
m, ok := bean.(*repo_model.PushMirror)
assert.True(t, ok)
assert.Equal(t, "test-1", m.RemoteName)
diff --git a/models/repo/release.go b/models/repo/release.go
index 246642205a..c63b324457 100644
--- a/models/repo/release.go
+++ b/models/repo/release.go
@@ -442,7 +442,7 @@ func UpdateReleasesMigrationsByType(gitServiceType structs.GitServiceType, origi
_, err := db.GetEngine(db.DefaultContext).Table("release").
Where("repo_id IN (SELECT id FROM repository WHERE original_service_type = ?)", gitServiceType).
And("original_author_id = ?", originalAuthorID).
- Update(map[string]interface{}{
+ Update(map[string]any{
"publisher_id": posterID,
"original_author": "",
"original_author_id": 0,
diff --git a/models/repo/repo_list.go b/models/repo/repo_list.go
index 92b9c15b4b..83ba02e316 100644
--- a/models/repo/repo_list.go
+++ b/models/repo/repo_list.go
@@ -560,7 +560,7 @@ func searchRepositoryByCondition(ctx context.Context, opts *SearchRepoOptions, c
opts.OrderBy = db.SearchOrderByAlphabetically
}
- args := make([]interface{}, 0)
+ args := make([]any, 0)
if opts.PriorityOwnerID > 0 {
opts.OrderBy = db.SearchOrderBy(fmt.Sprintf("CASE WHEN owner_id = ? THEN 0 ELSE owner_id END, %s", opts.OrderBy))
args = append(args, opts.PriorityOwnerID)
diff --git a/models/system/notice.go b/models/system/notice.go
index e598abe222..784ad74375 100644
--- a/models/system/notice.go
+++ b/models/system/notice.go
@@ -43,7 +43,7 @@ func (n *Notice) TrStr() string {
}
// CreateNotice creates new system notice.
-func CreateNotice(ctx context.Context, tp NoticeType, desc string, args ...interface{}) error {
+func CreateNotice(ctx context.Context, tp NoticeType, desc string, args ...any) error {
if len(args) > 0 {
desc = fmt.Sprintf(desc, args...)
}
@@ -55,7 +55,7 @@ func CreateNotice(ctx context.Context, tp NoticeType, desc string, args ...inter
}
// CreateRepositoryNotice creates new system notice with type NoticeRepository.
-func CreateRepositoryNotice(desc string, args ...interface{}) error {
+func CreateRepositoryNotice(desc string, args ...any) error {
// Note we use the db.DefaultContext here rather than passing in a context as the context may be cancelled
return CreateNotice(db.DefaultContext, NoticeRepository, desc, args...)
}
diff --git a/models/unittest/consistency.go b/models/unittest/consistency.go
index 41798c6253..faa02589aa 100644
--- a/models/unittest/consistency.go
+++ b/models/unittest/consistency.go
@@ -21,10 +21,10 @@ const (
modelsCommentTypeComment = 0
)
-var consistencyCheckMap = make(map[string]func(t assert.TestingT, bean interface{}))
+var consistencyCheckMap = make(map[string]func(t assert.TestingT, bean any))
// CheckConsistencyFor test that all matching database entries are consistent
-func CheckConsistencyFor(t assert.TestingT, beansToCheck ...interface{}) {
+func CheckConsistencyFor(t assert.TestingT, beansToCheck ...any) {
for _, bean := range beansToCheck {
sliceType := reflect.SliceOf(reflect.TypeOf(bean))
sliceValue := reflect.MakeSlice(sliceType, 0, 10)
@@ -42,7 +42,7 @@ func CheckConsistencyFor(t assert.TestingT, beansToCheck ...interface{}) {
}
}
-func checkForConsistency(t assert.TestingT, bean interface{}) {
+func checkForConsistency(t assert.TestingT, bean any) {
tb, err := db.TableInfo(bean)
assert.NoError(t, err)
f := consistencyCheckMap[tb.Name]
@@ -63,7 +63,7 @@ func init() {
return i
}
- checkForUserConsistency := func(t assert.TestingT, bean interface{}) {
+ checkForUserConsistency := func(t assert.TestingT, bean any) {
user := reflectionWrap(bean)
AssertCountByCond(t, "repository", builder.Eq{"owner_id": user.int("ID")}, user.int("NumRepos"))
AssertCountByCond(t, "star", builder.Eq{"uid": user.int("ID")}, user.int("NumStars"))
@@ -77,7 +77,7 @@ func init() {
}
}
- checkForRepoConsistency := func(t assert.TestingT, bean interface{}) {
+ checkForRepoConsistency := func(t assert.TestingT, bean any) {
repo := reflectionWrap(bean)
assert.Equal(t, repo.str("LowerName"), strings.ToLower(repo.str("Name")), "repo: %+v", repo)
AssertCountByCond(t, "star", builder.Eq{"repo_id": repo.int("ID")}, repo.int("NumStars"))
@@ -113,7 +113,7 @@ func init() {
"Unexpected number of closed milestones for repo id: %d", repo.int("ID"))
}
- checkForIssueConsistency := func(t assert.TestingT, bean interface{}) {
+ checkForIssueConsistency := func(t assert.TestingT, bean any) {
issue := reflectionWrap(bean)
typeComment := modelsCommentTypeComment
actual := GetCountByCond(t, "comment", builder.Eq{"`type`": typeComment, "issue_id": issue.int("ID")})
@@ -124,14 +124,14 @@ func init() {
}
}
- checkForPullRequestConsistency := func(t assert.TestingT, bean interface{}) {
+ checkForPullRequestConsistency := func(t assert.TestingT, bean any) {
pr := reflectionWrap(bean)
issueRow := AssertExistsAndLoadMap(t, "issue", builder.Eq{"id": pr.int("IssueID")})
assert.True(t, parseBool(issueRow["is_pull"]))
assert.EqualValues(t, parseInt(issueRow["index"]), pr.int("Index"), "Unexpected index for pull request id: %d", pr.int("ID"))
}
- checkForMilestoneConsistency := func(t assert.TestingT, bean interface{}) {
+ checkForMilestoneConsistency := func(t assert.TestingT, bean any) {
milestone := reflectionWrap(bean)
AssertCountByCond(t, "issue", builder.Eq{"milestone_id": milestone.int("ID")}, milestone.int("NumIssues"))
@@ -145,7 +145,7 @@ func init() {
assert.Equal(t, completeness, milestone.int("Completeness"))
}
- checkForLabelConsistency := func(t assert.TestingT, bean interface{}) {
+ checkForLabelConsistency := func(t assert.TestingT, bean any) {
label := reflectionWrap(bean)
issueLabels, err := db.GetEngine(db.DefaultContext).Table("issue_label").
Where(builder.Eq{"label_id": label.int("ID")}).
@@ -166,13 +166,13 @@ func init() {
assert.EqualValues(t, expected, label.int("NumClosedIssues"), "Unexpected number of closed issues for label id: %d", label.int("ID"))
}
- checkForTeamConsistency := func(t assert.TestingT, bean interface{}) {
+ checkForTeamConsistency := func(t assert.TestingT, bean any) {
team := reflectionWrap(bean)
AssertCountByCond(t, "team_user", builder.Eq{"team_id": team.int("ID")}, team.int("NumMembers"))
AssertCountByCond(t, "team_repo", builder.Eq{"team_id": team.int("ID")}, team.int("NumRepos"))
}
- checkForActionConsistency := func(t assert.TestingT, bean interface{}) {
+ checkForActionConsistency := func(t assert.TestingT, bean any) {
action := reflectionWrap(bean)
if action.int("RepoID") != 1700 { // dangling intentional
repoRow := AssertExistsAndLoadMap(t, "repository", builder.Eq{"id": action.int("RepoID")})
diff --git a/models/unittest/reflection.go b/models/unittest/reflection.go
index 1b149b19fe..141fc66b99 100644
--- a/models/unittest/reflection.go
+++ b/models/unittest/reflection.go
@@ -23,7 +23,7 @@ type reflectionValue struct {
v reflect.Value
}
-func reflectionWrap(v interface{}) *reflectionValue {
+func reflectionWrap(v any) *reflectionValue {
return &reflectionValue{v: reflect.ValueOf(v)}
}
diff --git a/models/unittest/testdb.go b/models/unittest/testdb.go
index f926a65538..1ff0fdc25b 100644
--- a/models/unittest/testdb.go
+++ b/models/unittest/testdb.go
@@ -37,7 +37,7 @@ func FixturesDir() string {
return fixturesDir
}
-func fatalTestError(fmtStr string, args ...interface{}) {
+func fatalTestError(fmtStr string, args ...any) {
_, _ = fmt.Fprintf(os.Stderr, fmtStr, args...)
os.Exit(1)
}
diff --git a/models/user/external_login_user.go b/models/user/external_login_user.go
index f70f3effcc..3a56240435 100644
--- a/models/user/external_login_user.go
+++ b/models/user/external_login_user.go
@@ -57,11 +57,11 @@ func (err ErrExternalLoginUserNotExist) Unwrap() error {
// ExternalLoginUser makes the connecting between some existing user and additional external login sources
type ExternalLoginUser struct {
- ExternalID string `xorm:"pk NOT NULL"`
- UserID int64 `xorm:"INDEX NOT NULL"`
- LoginSourceID int64 `xorm:"pk NOT NULL"`
- RawData map[string]interface{} `xorm:"TEXT JSON"`
- Provider string `xorm:"index VARCHAR(25)"`
+ ExternalID string `xorm:"pk NOT NULL"`
+ UserID int64 `xorm:"INDEX NOT NULL"`
+ LoginSourceID int64 `xorm:"pk NOT NULL"`
+ RawData map[string]any `xorm:"TEXT JSON"`
+ Provider string `xorm:"index VARCHAR(25)"`
Email string
Name string
FirstName string
diff --git a/models/webhook/hooktask.go b/models/webhook/hooktask.go
index f9fc886826..3ece5f062d 100644
--- a/models/webhook/hooktask.go
+++ b/models/webhook/hooktask.go
@@ -92,7 +92,7 @@ func (t *HookTask) AfterLoad() {
}
}
-func (t *HookTask) simpleMarshalJSON(v interface{}) string {
+func (t *HookTask) simpleMarshalJSON(v any) string {
p, err := json.Marshal(v)
if err != nil {
log.Error("Marshal [%d]: %v", t.ID, err)