all: replace interface{} with any (#7330)

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
This commit is contained in:
Joe Chen 2023-02-02 21:25:25 +08:00 committed by GitHub
parent 614382fec0
commit c53a1998c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
81 changed files with 195 additions and 195 deletions

View File

@ -84,7 +84,7 @@ type Provider interface {
Authenticate(login, password string) (*ExternalAccount, error)
// Config returns the underlying configuration of the authenticate provider.
Config() interface{}
Config() any
// HasTLS returns true if the authenticate provider supports TLS.
HasTLS() bool
// UseTLS returns true if the authenticate provider is configured to use TLS.

View File

@ -26,7 +26,7 @@ func (p *Provider) Authenticate(login, password string) (*auth.ExternalAccount,
fullname, email, website, location, err := p.config.doAuth(login, password)
if err != nil {
if strings.Contains(err.Error(), "401") {
return nil, auth.ErrBadCredentials{Args: map[string]interface{}{"login": login}}
return nil, auth.ErrBadCredentials{Args: map[string]any{"login": login}}
}
return nil, err
}
@ -40,7 +40,7 @@ func (p *Provider) Authenticate(login, password string) (*auth.ExternalAccount,
}, nil
}
func (p *Provider) Config() interface{} {
func (p *Provider) Config() any {
return p.config
}

View File

@ -29,7 +29,7 @@ func NewProvider(directBind bool, cfg *Config) auth.Provider {
func (p *Provider) Authenticate(login, password string) (*auth.ExternalAccount, error) {
username, fn, sn, email, isAdmin, succeed := p.config.searchEntry(login, password, p.directBind)
if !succeed {
return nil, auth.ErrBadCredentials{Args: map[string]interface{}{"login": login}}
return nil, auth.ErrBadCredentials{Args: map[string]any{"login": login}}
}
if username == "" {
@ -61,7 +61,7 @@ func (p *Provider) Authenticate(login, password string) (*auth.ExternalAccount,
}, nil
}
func (p *Provider) Config() interface{} {
func (p *Provider) Config() any {
return p.config
}

View File

@ -26,7 +26,7 @@ func (p *Provider) Authenticate(login, password string) (*auth.ExternalAccount,
err := p.config.doAuth(login, password)
if err != nil {
if strings.Contains(err.Error(), "Authentication failure") {
return nil, auth.ErrBadCredentials{Args: map[string]interface{}{"login": login}}
return nil, auth.ErrBadCredentials{Args: map[string]any{"login": login}}
}
return nil, err
}
@ -37,7 +37,7 @@ func (p *Provider) Authenticate(login, password string) (*auth.ExternalAccount,
}, nil
}
func (p *Provider) Config() interface{} {
func (p *Provider) Config() any {
return p.config
}

View File

@ -34,7 +34,7 @@ func (p *Provider) Authenticate(login, password string) (*auth.ExternalAccount,
if p.config.AllowedDomains != "" {
fields := strings.SplitN(login, "@", 3)
if len(fields) != 2 {
return nil, auth.ErrBadCredentials{Args: map[string]interface{}{"login": login}}
return nil, auth.ErrBadCredentials{Args: map[string]any{"login": login}}
}
domain := fields[1]
@ -47,7 +47,7 @@ func (p *Provider) Authenticate(login, password string) (*auth.ExternalAccount,
}
if !isAllowed {
return nil, auth.ErrBadCredentials{Args: map[string]interface{}{"login": login}}
return nil, auth.ErrBadCredentials{Args: map[string]any{"login": login}}
}
}
@ -68,7 +68,7 @@ func (p *Provider) Authenticate(login, password string) (*auth.ExternalAccount,
tperr, ok := err.(*textproto.Error)
if (ok && tperr.Code == 535) ||
strings.Contains(err.Error(), "Username and Password not accepted") {
return nil, auth.ErrBadCredentials{Args: map[string]interface{}{"login": login}}
return nil, auth.ErrBadCredentials{Args: map[string]any{"login": login}}
}
return nil, err
}
@ -88,7 +88,7 @@ func (p *Provider) Authenticate(login, password string) (*auth.ExternalAccount,
}, nil
}
func (p *Provider) Config() interface{} {
func (p *Provider) Config() any {
return p.config
}

View File

@ -41,7 +41,7 @@ Outputs to 'cert.pem' and 'key.pem' and will overwrite existing files.`,
},
}
func publicKey(priv interface{}) interface{} {
func publicKey(priv any) any {
switch k := priv.(type) {
case *rsa.PrivateKey:
return &k.PublicKey
@ -52,7 +52,7 @@ func publicKey(priv interface{}) interface{} {
}
}
func pemBlockForKey(priv interface{}) *pem.Block {
func pemBlockForKey(priv any) *pem.Block {
switch k := priv.(type) {
case *rsa.PrivateKey:
return &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(k)}
@ -72,7 +72,7 @@ func runCert(ctx *cli.Context) error {
log.Fatal("Missing required --host parameter")
}
var priv interface{}
var priv any
var err error
switch ctx.String("ecdsa-curve") {
case "":

View File

@ -38,7 +38,7 @@ var Serv = cli.Command{
// fail prints user message to the Git client (i.e. os.Stderr) and
// logs error message on the server side. When not in "prod" mode,
// error message is also printed to the client for easier debugging.
func fail(userMessage, errMessage string, args ...interface{}) {
func fail(userMessage, errMessage string, args ...any) {
_, _ = fmt.Fprintln(os.Stderr, "Gogs:", userMessage)
if len(errMessage) > 0 {

View File

@ -29,7 +29,7 @@ func TestInit(t *testing.T) {
for _, v := range []struct {
section string
config interface{}
config any
}{
{"", &App},
{"server", &Server},

View File

@ -16,7 +16,7 @@ import (
type loggerConf struct {
Buffer int64
Config interface{}
Config any
}
type logConf struct {

View File

@ -58,7 +58,7 @@ func (c *APIContext) Error(err error, msg string) {
}
// Errorf renders the 500 response with formatted message.
func (c *APIContext) Errorf(err error, format string, args ...interface{}) {
func (c *APIContext) Errorf(err error, format string, args ...any) {
c.Error(err, fmt.Sprintf(format, args...))
}

View File

@ -138,7 +138,7 @@ func (c *Context) Success(name string) {
}
// JSONSuccess responses JSON with status http.StatusOK.
func (c *Context) JSONSuccess(data interface{}) {
func (c *Context) JSONSuccess(data any) {
c.JSON(http.StatusOK, data)
}
@ -160,7 +160,7 @@ func (c *Context) RedirectSubpath(location string, status ...int) {
}
// RenderWithErr used for page has form validation but need to prompt error to users.
func (c *Context) RenderWithErr(msg, tpl string, f interface{}) {
func (c *Context) RenderWithErr(msg, tpl string, f any) {
if f != nil {
form.Assign(f, c.Data)
}
@ -189,7 +189,7 @@ func (c *Context) Error(err error, msg string) {
}
// Errorf renders the 500 response with formatted message.
func (c *Context) Errorf(err error, format string, args ...interface{}) {
func (c *Context) Errorf(err error, format string, args ...any) {
c.Error(err, fmt.Sprintf(format, args...))
}
@ -203,7 +203,7 @@ func (c *Context) NotFoundOrError(err error, msg string) {
}
// NotFoundOrErrorf is same as NotFoundOrError but with formatted message.
func (c *Context) NotFoundOrErrorf(err error, format string, args ...interface{}) {
func (c *Context) NotFoundOrErrorf(err error, format string, args ...any) {
c.NotFoundOrError(err, fmt.Sprintf(format, args...))
}
@ -211,7 +211,7 @@ func (c *Context) PlainText(status int, msg string) {
c.Render.PlainText(status, []byte(msg))
}
func (c *Context) ServeContent(name string, r io.ReadSeeker, params ...interface{}) {
func (c *Context) ServeContent(name string, r io.ReadSeeker, params ...any) {
modtime := time.Now()
for _, p := range params {
switch v := p.(type) {

View File

@ -96,7 +96,7 @@ func (r *Repository) Editorconfig() (*editorconfig.Editorconfig, error) {
}
// MakeURL accepts a string or url.URL as argument and returns escaped URL prepended with repository URL.
func (r *Repository) MakeURL(location interface{}) string {
func (r *Repository) MakeURL(location any) string {
switch location := location.(type) {
case string:
tempURL := url.URL{

View File

@ -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...),
}

View File

@ -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...),
}

View File

@ -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
}

View File

@ -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")

View File

@ -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,

View File

@ -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()
}

View File

@ -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),

View File

@ -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...),
}

View File

@ -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...),
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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...),
}

View File

@ -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)
}

View File

@ -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

View File

@ -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...),
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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)

View File

@ -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
)

View File

@ -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
}

View File

@ -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...),
}

View File

@ -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...),
}

View File

@ -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...),
}

View File

@ -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 {

View File

@ -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()

View File

@ -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

View File

@ -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
}

View File

@ -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(),
}).

View File

@ -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...),
}

View File

@ -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))

View File

@ -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
}

View File

@ -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...),
}

View File

@ -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
}

View File

@ -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.

View File

@ -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(),
}).

View File

@ -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)
})

View File

@ -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...),
}

View File

@ -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)

View File

@ -23,7 +23,7 @@ import (
// NewDB creates a new test database and initializes the given list of tables
// for the suite. The test database is dropped after testing is completed unless
// failed.
func NewDB(t *testing.T, suite string, tables ...interface{}) *gorm.DB {
func NewDB(t *testing.T, suite string, tables ...any) *gorm.DB {
dbType := os.Getenv("GOGS_DATABASE_TYPE")
var dbName string

View File

@ -14,6 +14,6 @@ type Logger struct {
io.Writer
}
func (l *Logger) Printf(format string, args ...interface{}) {
func (l *Logger) Printf(format string, args ...any) {
_, _ = fmt.Fprintf(l.Writer, format, args...)
}

View File

@ -38,13 +38,13 @@ var (
)
// render renders a mail template with given data.
func render(tpl string, data map[string]interface{}) (string, error) {
func render(tpl string, data map[string]any) (string, error) {
tplRenderOnce.Do(func() {
opt := &macaron.RenderOptions{
Directory: filepath.Join(conf.WorkDir(), "templates", "mail"),
AppendDirectories: []string{filepath.Join(conf.CustomDir(), "templates", "mail")},
Extensions: []string{".tmpl", ".html"},
Funcs: []template.FuncMap{map[string]interface{}{
Funcs: []template.FuncMap{map[string]any{
"AppName": func() string {
return conf.App.BrandName
},
@ -102,7 +102,7 @@ type Issue interface {
}
func SendUserMail(_ *macaron.Context, u User, tpl, code, subject, info string) {
data := map[string]interface{}{
data := map[string]any{
"Username": u.DisplayName(),
"ActiveCodeLives": conf.Auth.ActivateCodeLives / 60,
"ResetPwdCodeLives": conf.Auth.ResetPasswordCodeLives / 60,
@ -130,7 +130,7 @@ func SendResetPasswordMail(c *macaron.Context, u User) {
// SendActivateAccountMail sends confirmation email.
func SendActivateEmailMail(c *macaron.Context, u User, email string) {
data := map[string]interface{}{
data := map[string]any{
"Username": u.DisplayName(),
"ActiveCodeLives": conf.Auth.ActivateCodeLives / 60,
"Code": u.GenerateEmailActivateCode(email),
@ -150,7 +150,7 @@ func SendActivateEmailMail(c *macaron.Context, u User, email string) {
// SendRegisterNotifyMail triggers a notify e-mail by admin created a account.
func SendRegisterNotifyMail(c *macaron.Context, u User) {
data := map[string]interface{}{
data := map[string]any{
"Username": u.DisplayName(),
}
body, err := render(MAIL_AUTH_REGISTER_NOTIFY, data)
@ -169,7 +169,7 @@ func SendRegisterNotifyMail(c *macaron.Context, u User) {
func SendCollaboratorMail(u, doer User, repo Repository) {
subject := fmt.Sprintf("%s added you to %s", doer.DisplayName(), repo.FullName())
data := map[string]interface{}{
data := map[string]any{
"Subject": subject,
"RepoName": repo.FullName(),
"Link": repo.HTMLURL(),
@ -186,8 +186,8 @@ func SendCollaboratorMail(u, doer User, repo Repository) {
Send(msg)
}
func composeTplData(subject, body, link string) map[string]interface{} {
data := make(map[string]interface{}, 10)
func composeTplData(subject, body, link string) map[string]any {
data := make(map[string]any, 10)
data["Subject"] = subject
data["Body"] = body
data["Link"] = link

View File

@ -16,4 +16,4 @@ func IsNotFound(err error) bool {
}
// Args is a map of key-value pairs to provide additional context of an error.
type Args map[string]interface{}
type Args map[string]any

View File

@ -26,7 +26,7 @@ func init() {
IsMatch: func(rule string) bool {
return rule == "AlphaDashDotSlash"
},
IsValid: func(errs binding.Errors, name string, v interface{}) (bool, binding.Errors) {
IsValid: func(errs binding.Errors, name string, v any) (bool, binding.Errors) {
if AlphaDashDotSlashPattern.MatchString(fmt.Sprintf("%v", v)) {
errs.Add([]string{name}, ERR_ALPHA_DASH_DOT_SLASH, "AlphaDashDotSlash")
return false, errs
@ -41,7 +41,7 @@ type Form interface {
}
// Assign assign form values back to the template data.
func Assign(form interface{}, data map[string]interface{}) {
func Assign(form any, data map[string]any) {
typ := reflect.TypeOf(form)
val := reflect.ValueOf(form)
@ -90,7 +90,7 @@ func getInclude(field reflect.StructField) string {
return getRuleBody(field, "Include(")
}
func validate(errs binding.Errors, data map[string]interface{}, f Form, l macaron.Locale) binding.Errors {
func validate(errs binding.Errors, data map[string]any, f Form, l macaron.Locale) binding.Errors {
if errs.Len() == 0 {
return errs
}

View File

@ -220,7 +220,7 @@ func (r *Request) PostFile(formname, filename string) *Request {
// Body adds request raw body.
// it supports string and []byte.
func (r *Request) Body(data interface{}) *Request {
func (r *Request) Body(data any) *Request {
switch t := data.(type) {
case string:
bf := bytes.NewBufferString(t)
@ -414,7 +414,7 @@ func (r *Request) ToFile(filename string) error {
// ToJson returns the map that marshals from the body bytes as json in response .
// it calls Response inner.
func (r *Request) ToJson(v interface{}) error {
func (r *Request) ToJson(v any) error {
data, err := r.Bytes()
if err != nil {
return err
@ -424,7 +424,7 @@ func (r *Request) ToJson(v interface{}) error {
// ToXml returns the map that marshals from the body bytes as xml in response .
// it calls Response inner.
func (r *Request) ToXml(v interface{}) error {
func (r *Request) ToXml(v any) error {
data, err := r.Bytes()
if err != nil {
return err

View File

@ -161,6 +161,6 @@ func RawMarkdown(body []byte, urlPrefix string) []byte {
}
// Markdown takes a string or []byte and renders to HTML in Markdown syntax with special links.
func Markdown(input interface{}, urlPrefix string, metas map[string]string) []byte {
func Markdown(input any, urlPrefix string, metas map[string]string) []byte {
return Render(TypeMarkdown, input, urlPrefix, metas)
}

View File

@ -335,7 +335,7 @@ func Detect(filename string) Type {
}
// Render takes a string or []byte and renders to sanitized HTML in given type of syntax with special links.
func Render(typ Type, input interface{}, urlPrefix string, metas map[string]string) []byte {
func Render(typ Type, input any, urlPrefix string, metas map[string]string) []byte {
var rawBytes []byte
switch v := input.(type) {
case []byte:

View File

@ -35,6 +35,6 @@ func RawOrgMode(body []byte, urlPrefix string) (result []byte) {
}
// OrgMode takes a string or []byte and renders to HTML in Org-mode syntax with special links.
func OrgMode(input interface{}, urlPrefix string, metas map[string]string) []byte {
func OrgMode(input any, urlPrefix string, metas map[string]string) []byte {
return Render(TypeOrgMode, input, urlPrefix, metas)
}

View File

@ -12,13 +12,13 @@ var _ macaron.Locale = (*Locale)(nil)
type Locale struct {
MockLang string
MockTr func(string, ...interface{}) string
MockTr func(string, ...any) string
}
func (l *Locale) Language() string {
return l.MockLang
}
func (l *Locale) Tr(format string, args ...interface{}) string {
func (l *Locale) Tr(format string, args ...any) string {
return l.MockTr(format, args...)
}

View File

@ -47,7 +47,7 @@ func Authentications(c *context.Context) {
type dropdownItem struct {
Name string
Type interface{}
Type any
}
var (
@ -130,7 +130,7 @@ func NewAuthSourcePost(c *context.Context, f form.Authentication) {
c.Data["SMTPAuths"] = smtp.AuthTypes
hasTLS := false
var config interface{}
var config any
switch auth.Type(f.Type) {
case auth.LDAP, auth.DLDAP:
config = parseLDAPConfig(f)
@ -284,7 +284,7 @@ func DeleteAuthSource(c *context.Context) {
} else {
c.Flash.Error(fmt.Sprintf("DeleteSource: %v", err))
}
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"redirect": conf.Server.Subpath + "/admin/auths/" + c.Params(":authid"),
})
return
@ -292,7 +292,7 @@ func DeleteAuthSource(c *context.Context) {
log.Trace("Authentication deleted by admin(%s): %d", c.User.Name, id)
c.Flash.Success(c.Tr("admin.auths.deletion_success"))
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"redirect": conf.Server.Subpath + "/admin/auths",
})
}

View File

@ -81,7 +81,7 @@ func DeleteRepo(c *context.Context) {
log.Trace("Repository deleted: %s/%s", repo.MustOwner().Name, repo.Name)
c.Flash.Success(c.Tr("repo.settings.deletion_success"))
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"redirect": conf.Server.Subpath + "/admin/repos?page=" + c.Query("page"),
})
}

View File

@ -230,12 +230,12 @@ func DeleteUser(c *context.Context) {
switch {
case db.IsErrUserOwnRepos(err):
c.Flash.Error(c.Tr("admin.users.still_own_repo"))
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"redirect": conf.Server.Subpath + "/admin/users/" + c.Params(":userid"),
})
case db.IsErrUserHasOrgs(err):
c.Flash.Error(c.Tr("admin.users.still_has_org"))
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"redirect": conf.Server.Subpath + "/admin/users/" + c.Params(":userid"),
})
default:
@ -246,7 +246,7 @@ func DeleteUser(c *context.Context) {
log.Trace("Account deleted by admin (%s): %s", c.User.Name, u.Name)
c.Flash.Success(c.Tr("admin.users.deletion_success"))
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"redirect": conf.Server.Subpath + "/admin/users",
})
}

View File

@ -34,7 +34,7 @@ func Search(c *context.APIContext) {
} else {
u, err := db.Users.GetByID(c.Req.Context(), opts.OwnerID)
if err != nil {
c.JSON(http.StatusInternalServerError, map[string]interface{}{
c.JSON(http.StatusInternalServerError, map[string]any{
"ok": false,
"error": err.Error(),
})
@ -49,7 +49,7 @@ func Search(c *context.APIContext) {
repos, count, err := db.SearchRepositoryByName(opts)
if err != nil {
c.JSON(http.StatusInternalServerError, map[string]interface{}{
c.JSON(http.StatusInternalServerError, map[string]any{
"ok": false,
"error": err.Error(),
})
@ -57,7 +57,7 @@ func Search(c *context.APIContext) {
}
if err = db.RepositoryList(repos).LoadAttributes(); err != nil {
c.JSON(http.StatusInternalServerError, map[string]interface{}{
c.JSON(http.StatusInternalServerError, map[string]any{
"ok": false,
"error": err.Error(),
})
@ -70,7 +70,7 @@ func Search(c *context.APIContext) {
}
c.SetLinkHeader(int(count), opts.PageSize)
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"ok": true,
"data": results,
})

View File

@ -28,7 +28,7 @@ func Search(c *context.APIContext) {
users, _, err := db.SearchUserByName(opts)
if err != nil {
c.JSON(http.StatusInternalServerError, map[string]interface{}{
c.JSON(http.StatusInternalServerError, map[string]any{
"ok": false,
"error": err.Error(),
})
@ -48,7 +48,7 @@ func Search(c *context.APIContext) {
}
}
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"ok": true,
"data": results,
})

View File

@ -170,7 +170,7 @@ type responseError struct {
const contentType = "application/vnd.git-lfs+json"
func responseJSON(w http.ResponseWriter, status int, v interface{}) {
func responseJSON(w http.ResponseWriter, status int, v any) {
w.Header().Set("Content-Type", contentType)
w.WriteHeader(status)

View File

@ -76,7 +76,7 @@ func MembersAction(c *context.Context) {
if err != nil {
log.Error("Action(%s): %v", c.Params(":action"), err)
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"ok": false,
"err": err.Error(),
})

View File

@ -91,7 +91,7 @@ func TeamsAction(c *context.Context) {
c.Flash.Error(c.Tr("form.last_org_owner"))
} else {
log.Error("Action(%s): %v", c.Params(":action"), err)
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"ok": false,
"err": err.Error(),
})
@ -265,7 +265,7 @@ func DeleteTeam(c *context.Context) {
c.Flash.Success(c.Tr("org.teams.delete_team_success"))
}
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"redirect": c.Org.OrgLink + "/teams",
})
}

View File

@ -719,7 +719,7 @@ func UpdateIssueTitle(c *context.Context) {
return
}
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"title": issue.Title,
})
}
@ -778,7 +778,7 @@ func UpdateIssueLabel(c *context.Context) {
}
}
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"ok": true,
})
}
@ -792,7 +792,7 @@ func UpdateIssueMilestone(c *context.Context) {
oldMilestoneID := issue.MilestoneID
milestoneID := c.QueryInt64("id")
if oldMilestoneID == milestoneID {
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"ok": true,
})
return
@ -805,7 +805,7 @@ func UpdateIssueMilestone(c *context.Context) {
return
}
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"ok": true,
})
}
@ -818,7 +818,7 @@ func UpdateIssueAssignee(c *context.Context) {
assigneeID := c.QueryInt64("id")
if issue.AssigneeID == assigneeID {
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"ok": true,
})
return
@ -829,7 +829,7 @@ func UpdateIssueAssignee(c *context.Context) {
return
}
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"ok": true,
})
}
@ -943,7 +943,7 @@ func UpdateCommentContent(c *context.Context) {
oldContent := comment.Content
comment.Content = c.Query("content")
if comment.Content == "" {
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"content": "",
})
return
@ -1062,7 +1062,7 @@ func DeleteLabel(c *context.Context) {
c.Flash.Success(c.Tr("repo.issues.label_deletion_success"))
}
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"redirect": c.Repo.MakeURL("labels"),
})
}
@ -1260,7 +1260,7 @@ func DeleteMilestone(c *context.Context) {
c.Flash.Success(c.Tr("repo.milestones.deletion_success"))
}
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"redirect": c.Repo.MakeURL("milestones"),
})
}

View File

@ -320,7 +320,7 @@ func DeleteRelease(c *context.Context) {
c.Flash.Success(c.Tr("repo.release.deletion_success"))
}
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"redirect": c.Repo.RepoLink + "/releases",
})
}

View File

@ -86,7 +86,7 @@ func Create(c *context.Context) {
c.Success(CREATE)
}
func handleCreateError(c *context.Context, err error, name, tpl string, form interface{}) {
func handleCreateError(c *context.Context, err error, name, tpl string, form any) {
switch {
case db.IsErrReachLimitOfRepo(err):
c.RenderWithErr(c.Tr("repo.form.reach_limit_of_creation", err.(db.ErrReachLimitOfRepo).Limit), tpl, form)

View File

@ -429,7 +429,7 @@ func DeleteCollaboration(c *context.Context) {
c.Flash.Success(c.Tr("repo.settings.remove_collaborator_success"))
}
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"redirect": c.Repo.RepoLink + "/settings/collaboration",
})
}
@ -682,7 +682,7 @@ func DeleteDeployKey(c *context.Context) {
c.Flash.Success(c.Tr("repo.settings.deploy_key_deletion_success"))
}
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"redirect": c.Repo.RepoLink + "/settings/keys",
})
}

View File

@ -591,7 +591,7 @@ func DeleteWebhook(c *context.Context, orCtx *orgRepoContext) {
}
c.Flash.Success(c.Tr("repo.settings.webhook_deletion_success"))
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"redirect": orCtx.Link + "/settings/hooks",
})
}

View File

@ -16,7 +16,7 @@ import (
func Test_validateWebhook(t *testing.T) {
l := &mocks.Locale{
MockLang: "en",
MockTr: func(s string, _ ...interface{}) string {
MockTr: func(s string, _ ...any) string {
return s
},
}

View File

@ -263,7 +263,7 @@ func DeleteWikiPagePost(c *context.Context) {
return
}
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"redirect": c.Repo.RepoLink + "/wiki/",
})
}

View File

@ -300,7 +300,7 @@ func DeleteEmail(c *context.Context) {
}
c.Flash.Success(c.Tr("settings.email_deletion_success"))
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"redirect": conf.Server.Subpath + "/user/settings/email",
})
}
@ -372,7 +372,7 @@ func DeleteSSHKey(c *context.Context) {
c.Flash.Success(c.Tr("settings.ssh_key_deletion_success"))
}
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"redirect": conf.Server.Subpath + "/user/settings/ssh",
})
}
@ -507,7 +507,7 @@ func SettingsTwoFactorDisable(c *context.Context) {
}
c.Flash.Success(c.Tr("settings.two_factor_disable_success"))
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"redirect": conf.Server.Subpath + "/user/settings/security",
})
}
@ -543,7 +543,7 @@ func SettingsLeaveRepo(c *context.Context) {
}
c.Flash.Success(c.Tr("settings.repos.leave_success", repo.FullName()))
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"redirect": conf.Server.Subpath + "/user/settings/repositories",
})
}
@ -572,7 +572,7 @@ func SettingsLeaveOrganization(c *context.Context) {
}
}
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"redirect": conf.Server.Subpath + "/user/settings/organizations",
})
}
@ -630,7 +630,7 @@ func SettingsDeleteApplication(c *context.Context) {
c.Flash.Success(c.Tr("settings.delete_token_success"))
}
c.JSONSuccess(map[string]interface{}{
c.JSONSuccess(map[string]any{
"redirect": conf.Server.Subpath + "/user/settings/applications",
})
}

View File

@ -38,13 +38,13 @@ func (q *UniqueQueue) Queue() <-chan string {
// Exist returns true if there is an instance with given indentity
// exists in the queue.
func (q *UniqueQueue) Exist(id interface{}) bool {
func (q *UniqueQueue) Exist(id any) bool {
return q.table.IsRunning(com.ToStr(id))
}
// AddFunc adds new instance to the queue with a custom runnable function,
// the queue is blocked until the function exits.
func (q *UniqueQueue) AddFunc(id interface{}, fn func()) {
func (q *UniqueQueue) AddFunc(id any, fn func()) {
if q.Exist(id) {
return
}
@ -60,11 +60,11 @@ func (q *UniqueQueue) AddFunc(id interface{}, fn func()) {
}
// Add adds new instance to the queue.
func (q *UniqueQueue) Add(id interface{}) {
func (q *UniqueQueue) Add(id any) {
q.AddFunc(id, nil)
}
// Remove removes instance from the queue.
func (q *UniqueQueue) Remove(id interface{}) {
func (q *UniqueQueue) Remove(id any) {
q.table.Stop(com.ToStr(id))
}

View File

@ -39,7 +39,7 @@ var (
// FuncMap returns a list of user-defined template functions.
func FuncMap() []template.FuncMap {
funcMapOnce.Do(func() {
funcMap = []template.FuncMap{map[string]interface{}{
funcMap = []template.FuncMap{map[string]any{
"BuildCommit": func() string {
return conf.BuildCommit
},

View File

@ -29,7 +29,7 @@ func Update(name string) bool {
// AssertGolden compares what's got and what's in the golden file. It updates
// the golden file on-demand. It does nothing when the runtime is "windows".
func AssertGolden(t testing.TB, path string, update bool, got interface{}) {
func AssertGolden(t testing.TB, path string, update bool, got any) {
if runtime.GOOS == "windows" {
t.Skip("Skipping testing on Windows")
return
@ -59,7 +59,7 @@ func AssertGolden(t testing.TB, path string, update bool, got interface{}) {
assert.Equal(t, string(golden), string(data))
}
func marshal(t testing.TB, v interface{}) []byte {
func marshal(t testing.TB, v any) []byte {
t.Helper()
switch v2 := v.(type) {

View File

@ -26,6 +26,6 @@ func (*noopLogger) Write(log.Messager) error {
}
// InitNoopLogger is a init function to initialize a noop logger.
var InitNoopLogger = func(name string, vs ...interface{}) (log.Logger, error) {
var InitNoopLogger = func(name string, vs ...any) (log.Logger, error) {
return &noopLogger{}, nil
}

View File

@ -93,7 +93,7 @@ const TIME_LIMIT_CODE_LENGTH = 12 + 6 + 40
// CreateTimeLimitCode generates a time limit code based on given input data.
// Format: 12 length date time string + 6 minutes string + 40 sha1 encoded string
func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string {
func CreateTimeLimitCode(data string, minutes int, startInf any) string {
format := "200601021504"
var start, end time.Time
@ -306,7 +306,7 @@ func TimeSince(t time.Time, lang string) template.HTML {
}
// Subtract deals with subtraction of all types of number.
func Subtract(left, right interface{}) interface{} {
func Subtract(left, right any) any {
var rleft, rright int64
var fleft, fright float64
isInt := true