Skip to content

Commit b455b8f

Browse files
committed
Replace interface{} with any (go-gitea#25686)
1 parent 4e31013 commit b455b8f

File tree

233 files changed

+729
-729
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

233 files changed

+729
-729
lines changed

build/code-batch-process.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525

2626
var optionLogVerbose bool
2727

28-
func logVerbose(msg string, args ...interface{}) {
28+
func logVerbose(msg string, args ...any) {
2929
if optionLogVerbose {
3030
log.Printf(msg, args...)
3131
}

cmd/cert.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Outputs to 'cert.pem' and 'key.pem' and will overwrite existing files.`,
6363
},
6464
}
6565

66-
func publicKey(priv interface{}) interface{} {
66+
func publicKey(priv any) any {
6767
switch k := priv.(type) {
6868
case *rsa.PrivateKey:
6969
return &k.PublicKey
@@ -74,7 +74,7 @@ func publicKey(priv interface{}) interface{} {
7474
}
7575
}
7676

77-
func pemBlockForKey(priv interface{}) *pem.Block {
77+
func pemBlockForKey(priv any) *pem.Block {
7878
switch k := priv.(type) {
7979
case *rsa.PrivateKey:
8080
return &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(k)}
@@ -94,7 +94,7 @@ func runCert(c *cli.Context) error {
9494
return err
9595
}
9696

97-
var priv interface{}
97+
var priv any
9898
var err error
9999
switch c.String("ecdsa-curve") {
100100
case "":

cmd/dump.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ It can be used for backup and capture Gitea server image to send to maintainer`,
161161
},
162162
}
163163

164-
func fatal(format string, args ...interface{}) {
164+
func fatal(format string, args ...any) {
165165
fmt.Fprintf(os.Stderr, format+"\n", args...)
166166
log.Fatal(format, args...)
167167
}
@@ -236,7 +236,7 @@ func runDump(ctx *cli.Context) error {
236236
return err
237237
}
238238

239-
var iface interface{}
239+
var iface any
240240
if fileName == "-" {
241241
iface, err = archiver.ByExtension(fmt.Sprintf(".%s", outType))
242242
} else {

cmd/manager_logging.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func runAddConnLogger(c *cli.Context) error {
178178
defer cancel()
179179

180180
setup(ctx, c.Bool("debug"))
181-
vals := map[string]interface{}{}
181+
vals := map[string]any{}
182182
mode := "conn"
183183
vals["net"] = "tcp"
184184
if c.IsSet("protocol") {
@@ -208,7 +208,7 @@ func runAddFileLogger(c *cli.Context) error {
208208
defer cancel()
209209

210210
setup(ctx, c.Bool("debug"))
211-
vals := map[string]interface{}{}
211+
vals := map[string]any{}
212212
mode := "file"
213213
if c.IsSet("filename") {
214214
vals["filename"] = c.String("filename")
@@ -236,7 +236,7 @@ func runAddFileLogger(c *cli.Context) error {
236236
return commonAddLogger(c, mode, vals)
237237
}
238238

239-
func commonAddLogger(c *cli.Context, mode string, vals map[string]interface{}) error {
239+
func commonAddLogger(c *cli.Context, mode string, vals map[string]any) error {
240240
if len(c.String("level")) > 0 {
241241
vals["level"] = log.LevelFromString(c.String("level")).String()
242242
}

cmd/serv.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ var (
9595

9696
// fail prints message to stdout, it's mainly used for git serv and git hook commands.
9797
// The output will be passed to git client and shown to user.
98-
func fail(ctx context.Context, userMessage, logMsgFmt string, args ...interface{}) error {
98+
func fail(ctx context.Context, userMessage, logMsgFmt string, args ...any) error {
9999
if userMessage == "" {
100100
userMessage = "Internal Server Error (no specific error)"
101101
}

models/admin/task.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func init() {
4444
// TranslatableMessage represents JSON struct that can be translated with a Locale
4545
type TranslatableMessage struct {
4646
Format string
47-
Args []interface{} `json:"omitempty"`
47+
Args []any `json:"omitempty"`
4848
}
4949

5050
// LoadRepo loads repository of the task

models/asymkey/ssh_key_authorized_keys.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var sshOpLocker sync.Mutex
4747
// AuthorizedStringForKey creates the authorized keys string appropriate for the provided key
4848
func AuthorizedStringForKey(key *PublicKey) string {
4949
sb := &strings.Builder{}
50-
_ = setting.SSH.AuthorizedKeysCommandTemplateTemplate.Execute(sb, map[string]interface{}{
50+
_ = setting.SSH.AuthorizedKeysCommandTemplateTemplate.Execute(sb, map[string]any{
5151
"AppPath": util.ShellEscape(setting.AppPath),
5252
"AppWorkPath": util.ShellEscape(setting.AppWorkPath),
5353
"CustomConf": util.ShellEscape(setting.CustomConf),
@@ -175,7 +175,7 @@ func RewriteAllPublicKeys() error {
175175

176176
// RegeneratePublicKeys regenerates the authorized_keys file
177177
func RegeneratePublicKeys(ctx context.Context, t io.StringWriter) error {
178-
if err := db.GetEngine(ctx).Where("type != ?", KeyTypePrincipal).Iterate(new(PublicKey), func(idx int, bean interface{}) (err error) {
178+
if err := db.GetEngine(ctx).Where("type != ?", KeyTypePrincipal).Iterate(new(PublicKey), func(idx int, bean any) (err error) {
179179
_, err = t.WriteString((bean.(*PublicKey)).AuthorizedString())
180180
return err
181181
}); err != nil {

models/asymkey/ssh_key_authorized_principals.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func RewriteAllPrincipalKeys(ctx context.Context) error {
9797
}
9898

9999
func regeneratePrincipalKeys(ctx context.Context, t io.StringWriter) error {
100-
if err := db.GetEngine(ctx).Where("type = ?", KeyTypePrincipal).Iterate(new(PublicKey), func(idx int, bean interface{}) (err error) {
100+
if err := db.GetEngine(ctx).Where("type = ?", KeyTypePrincipal).Iterate(new(PublicKey), func(idx int, bean any) (err error) {
101101
_, err = t.WriteString((bean.(*PublicKey)).AuthorizedString())
102102
return err
103103
}); err != nil {

models/db/context.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (ctx *Context) Engine() Engine {
5252
}
5353

5454
// Value shadows Value for context.Context but allows us to get ourselves and an Engined object
55-
func (ctx *Context) Value(key interface{}) interface{} {
55+
func (ctx *Context) Value(key any) any {
5656
if key == enginedContextKey {
5757
return ctx
5858
}
@@ -163,28 +163,28 @@ func txWithNoCheck(parentCtx context.Context, f func(ctx context.Context) error)
163163
}
164164

165165
// Insert inserts records into database
166-
func Insert(ctx context.Context, beans ...interface{}) error {
166+
func Insert(ctx context.Context, beans ...any) error {
167167
_, err := GetEngine(ctx).Insert(beans...)
168168
return err
169169
}
170170

171171
// Exec executes a sql with args
172-
func Exec(ctx context.Context, sqlAndArgs ...interface{}) (sql.Result, error) {
172+
func Exec(ctx context.Context, sqlAndArgs ...any) (sql.Result, error) {
173173
return GetEngine(ctx).Exec(sqlAndArgs...)
174174
}
175175

176176
// GetByBean filled empty fields of the bean according non-empty fields to query in database.
177-
func GetByBean(ctx context.Context, bean interface{}) (bool, error) {
177+
func GetByBean(ctx context.Context, bean any) (bool, error) {
178178
return GetEngine(ctx).Get(bean)
179179
}
180180

181181
// DeleteByBean deletes all records according non-empty fields of the bean as conditions.
182-
func DeleteByBean(ctx context.Context, bean interface{}) (int64, error) {
182+
func DeleteByBean(ctx context.Context, bean any) (int64, error) {
183183
return GetEngine(ctx).Delete(bean)
184184
}
185185

186186
// DeleteByID deletes the given bean with the given ID
187-
func DeleteByID(ctx context.Context, id int64, bean interface{}) (int64, error) {
187+
func DeleteByID(ctx context.Context, id int64, bean any) (int64, error) {
188188
return GetEngine(ctx).ID(id).NoAutoTime().Delete(bean)
189189
}
190190

@@ -203,13 +203,13 @@ func FindIDs(ctx context.Context, tableName, idCol string, cond builder.Cond) ([
203203

204204
// DecrByIDs decreases the given column for entities of the "bean" type with one of the given ids by one
205205
// Timestamps of the entities won't be updated
206-
func DecrByIDs(ctx context.Context, ids []int64, decrCol string, bean interface{}) error {
206+
func DecrByIDs(ctx context.Context, ids []int64, decrCol string, bean any) error {
207207
_, err := GetEngine(ctx).Decr(decrCol).In("id", ids).NoAutoCondition().NoAutoTime().Update(bean)
208208
return err
209209
}
210210

211211
// DeleteBeans deletes all given beans, beans must contain delete conditions.
212-
func DeleteBeans(ctx context.Context, beans ...interface{}) (err error) {
212+
func DeleteBeans(ctx context.Context, beans ...any) (err error) {
213213
e := GetEngine(ctx)
214214
for i := range beans {
215215
if _, err = e.Delete(beans[i]); err != nil {
@@ -220,7 +220,7 @@ func DeleteBeans(ctx context.Context, beans ...interface{}) (err error) {
220220
}
221221

222222
// TruncateBeans deletes all given beans, beans may contain delete conditions.
223-
func TruncateBeans(ctx context.Context, beans ...interface{}) (err error) {
223+
func TruncateBeans(ctx context.Context, beans ...any) (err error) {
224224
e := GetEngine(ctx)
225225
for i := range beans {
226226
if _, err = e.Truncate(beans[i]); err != nil {
@@ -231,12 +231,12 @@ func TruncateBeans(ctx context.Context, beans ...interface{}) (err error) {
231231
}
232232

233233
// CountByBean counts the number of database records according non-empty fields of the bean as conditions.
234-
func CountByBean(ctx context.Context, bean interface{}) (int64, error) {
234+
func CountByBean(ctx context.Context, bean any) (int64, error) {
235235
return GetEngine(ctx).Count(bean)
236236
}
237237

238238
// TableName returns the table name according a bean object
239-
func TableName(bean interface{}) string {
239+
func TableName(bean any) string {
240240
return x.TableName(bean)
241241
}
242242

models/db/engine.go

+31-31
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525

2626
var (
2727
x *xorm.Engine
28-
tables []interface{}
28+
tables []any
2929
initFuncs []func() error
3030

3131
// HasEngine specifies if we have a xorm.Engine
@@ -34,41 +34,41 @@ var (
3434

3535
// Engine represents a xorm engine or session.
3636
type Engine interface {
37-
Table(tableNameOrBean interface{}) *xorm.Session
38-
Count(...interface{}) (int64, error)
39-
Decr(column string, arg ...interface{}) *xorm.Session
40-
Delete(...interface{}) (int64, error)
41-
Truncate(...interface{}) (int64, error)
42-
Exec(...interface{}) (sql.Result, error)
43-
Find(interface{}, ...interface{}) error
44-
Get(beans ...interface{}) (bool, error)
45-
ID(interface{}) *xorm.Session
46-
In(string, ...interface{}) *xorm.Session
47-
Incr(column string, arg ...interface{}) *xorm.Session
48-
Insert(...interface{}) (int64, error)
49-
Iterate(interface{}, xorm.IterFunc) error
50-
Join(joinOperator string, tablename, condition interface{}, args ...interface{}) *xorm.Session
51-
SQL(interface{}, ...interface{}) *xorm.Session
52-
Where(interface{}, ...interface{}) *xorm.Session
37+
Table(tableNameOrBean any) *xorm.Session
38+
Count(...any) (int64, error)
39+
Decr(column string, arg ...any) *xorm.Session
40+
Delete(...any) (int64, error)
41+
Truncate(...any) (int64, error)
42+
Exec(...any) (sql.Result, error)
43+
Find(any, ...any) error
44+
Get(beans ...any) (bool, error)
45+
ID(any) *xorm.Session
46+
In(string, ...any) *xorm.Session
47+
Incr(column string, arg ...any) *xorm.Session
48+
Insert(...any) (int64, error)
49+
Iterate(any, xorm.IterFunc) error
50+
Join(joinOperator string, tablename, condition any, args ...any) *xorm.Session
51+
SQL(any, ...any) *xorm.Session
52+
Where(any, ...any) *xorm.Session
5353
Asc(colNames ...string) *xorm.Session
5454
Desc(colNames ...string) *xorm.Session
5555
Limit(limit int, start ...int) *xorm.Session
5656
NoAutoTime() *xorm.Session
57-
SumInt(bean interface{}, columnName string) (res int64, err error)
58-
Sync2(...interface{}) error
57+
SumInt(bean any, columnName string) (res int64, err error)
58+
Sync2(...any) error
5959
Select(string) *xorm.Session
60-
NotIn(string, ...interface{}) *xorm.Session
61-
OrderBy(interface{}, ...interface{}) *xorm.Session
62-
Exist(...interface{}) (bool, error)
60+
NotIn(string, ...any) *xorm.Session
61+
OrderBy(any, ...any) *xorm.Session
62+
Exist(...any) (bool, error)
6363
Distinct(...string) *xorm.Session
64-
Query(...interface{}) ([]map[string][]byte, error)
64+
Query(...any) ([]map[string][]byte, error)
6565
Cols(...string) *xorm.Session
6666
Context(ctx context.Context) *xorm.Session
6767
Ping() error
6868
}
6969

7070
// TableInfo returns table's information via an object
71-
func TableInfo(v interface{}) (*schemas.Table, error) {
71+
func TableInfo(v any) (*schemas.Table, error) {
7272
return x.TableInfo(v)
7373
}
7474

@@ -78,7 +78,7 @@ func DumpTables(tables []*schemas.Table, w io.Writer, tp ...schemas.DBType) erro
7878
}
7979

8080
// RegisterModel registers model, if initfunc provided, it will be invoked after data model sync
81-
func RegisterModel(bean interface{}, initFunc ...func() error) {
81+
func RegisterModel(bean any, initFunc ...func() error) {
8282
tables = append(tables, bean)
8383
if len(initFuncs) > 0 && initFunc[0] != nil {
8484
initFuncs = append(initFuncs, initFunc[0])
@@ -209,22 +209,22 @@ func InitEngineWithMigration(ctx context.Context, migrateFunc func(*xorm.Engine)
209209
}
210210

211211
// NamesToBean return a list of beans or an error
212-
func NamesToBean(names ...string) ([]interface{}, error) {
213-
beans := []interface{}{}
212+
func NamesToBean(names ...string) ([]any, error) {
213+
beans := []any{}
214214
if len(names) == 0 {
215215
beans = append(beans, tables...)
216216
return beans, nil
217217
}
218218
// Need to map provided names to beans...
219-
beanMap := make(map[string]interface{})
219+
beanMap := make(map[string]any)
220220
for _, bean := range tables {
221221

222222
beanMap[strings.ToLower(reflect.Indirect(reflect.ValueOf(bean)).Type().Name())] = bean
223223
beanMap[strings.ToLower(x.TableName(bean))] = bean
224224
beanMap[strings.ToLower(x.TableName(bean, true))] = bean
225225
}
226226

227-
gotBean := make(map[interface{}]bool)
227+
gotBean := make(map[any]bool)
228228
for _, name := range names {
229229
bean, ok := beanMap[strings.ToLower(strings.TrimSpace(name))]
230230
if !ok {
@@ -266,7 +266,7 @@ func DumpDatabase(filePath, dbType string) error {
266266
}
267267

268268
// MaxBatchInsertSize returns the table's max batch insert size
269-
func MaxBatchInsertSize(bean interface{}) int {
269+
func MaxBatchInsertSize(bean any) int {
270270
t, err := x.TableInfo(bean)
271271
if err != nil {
272272
return 50
@@ -286,7 +286,7 @@ func DeleteAllRecords(tableName string) error {
286286
}
287287

288288
// GetMaxID will return max id of the table
289-
func GetMaxID(beanOrTableName interface{}) (maxID int64, err error) {
289+
func GetMaxID(beanOrTableName any) (maxID int64, err error) {
290290
_, err = x.Select("MAX(id)").Table(beanOrTableName).Get(&maxID)
291291
return maxID, err
292292
}

models/db/error.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (err ErrCancelled) Error() string {
2525
}
2626

2727
// ErrCancelledf returns an ErrCancelled for the provided format and args
28-
func ErrCancelledf(format string, args ...interface{}) error {
28+
func ErrCancelledf(format string, args ...any) error {
2929
return ErrCancelled{
3030
fmt.Sprintf(format, args...),
3131
}

0 commit comments

Comments
 (0)