1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

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](2580d0e08d).
This commit is contained in:
silverwind
2023-07-04 20:36:08 +02:00
committed by GitHub
parent 00dbba7f42
commit 88f835192d
233 changed files with 727 additions and 727 deletions

View File

@@ -38,8 +38,8 @@ func (err ErrInvalidAlgorithmType) Error() string {
type JWTSigningKey interface {
IsSymmetric() bool
SigningMethod() jwt.SigningMethod
SignKey() interface{}
VerifyKey() interface{}
SignKey() any
VerifyKey() any
ToJWK() (map[string]string, error)
PreProcessToken(*jwt.Token)
}
@@ -57,11 +57,11 @@ func (key hmacSigningKey) SigningMethod() jwt.SigningMethod {
return key.signingMethod
}
func (key hmacSigningKey) SignKey() interface{} {
func (key hmacSigningKey) SignKey() any {
return key.secret
}
func (key hmacSigningKey) VerifyKey() interface{} {
func (key hmacSigningKey) VerifyKey() any {
return key.secret
}
@@ -101,11 +101,11 @@ func (key rsaSingingKey) SigningMethod() jwt.SigningMethod {
return key.signingMethod
}
func (key rsaSingingKey) SignKey() interface{} {
func (key rsaSingingKey) SignKey() any {
return key.key
}
func (key rsaSingingKey) VerifyKey() interface{} {
func (key rsaSingingKey) VerifyKey() any {
return key.key.Public()
}
@@ -152,11 +152,11 @@ func (key eddsaSigningKey) SigningMethod() jwt.SigningMethod {
return key.signingMethod
}
func (key eddsaSigningKey) SignKey() interface{} {
func (key eddsaSigningKey) SignKey() any {
return key.key
}
func (key eddsaSigningKey) VerifyKey() interface{} {
func (key eddsaSigningKey) VerifyKey() any {
return key.key.Public()
}
@@ -203,11 +203,11 @@ func (key ecdsaSingingKey) SigningMethod() jwt.SigningMethod {
return key.signingMethod
}
func (key ecdsaSingingKey) SignKey() interface{} {
func (key ecdsaSingingKey) SignKey() any {
return key.key
}
func (key ecdsaSingingKey) VerifyKey() interface{} {
func (key ecdsaSingingKey) VerifyKey() any {
return key.key.Public()
}
@@ -229,7 +229,7 @@ func (key ecdsaSingingKey) PreProcessToken(token *jwt.Token) {
}
// CreateJWTSigningKey creates a signing key from an algorithm / key pair.
func CreateJWTSigningKey(algorithm string, key interface{}) (JWTSigningKey, error) {
func CreateJWTSigningKey(algorithm string, key any) (JWTSigningKey, error) {
var signingMethod jwt.SigningMethod
switch algorithm {
case "HS256":
@@ -292,7 +292,7 @@ var DefaultSigningKey JWTSigningKey
// InitSigningKey creates the default signing key from settings or creates a random key.
func InitSigningKey() error {
var err error
var key interface{}
var key any
switch setting.OAuth2.JWTSigningAlgorithm {
case "HS256":
@@ -335,7 +335,7 @@ func InitSigningKey() error {
// loadSymmetricKey checks if the configured secret is valid.
// If it is not valid, it will return an error.
func loadSymmetricKey() (interface{}, error) {
func loadSymmetricKey() (any, error) {
key := make([]byte, 32)
n, err := base64.RawURLEncoding.Decode(key, []byte(setting.OAuth2.JWTSecretBase64))
if err != nil {
@@ -350,7 +350,7 @@ func loadSymmetricKey() (interface{}, error) {
// loadOrCreateAsymmetricKey checks if the configured private key exists.
// If it does not exist a new random key gets generated and saved on the configured path.
func loadOrCreateAsymmetricKey() (interface{}, error) {
func loadOrCreateAsymmetricKey() (any, error) {
keyPath := setting.OAuth2.JWTSigningPrivateKeyFile
isExist, err := util.IsExist(keyPath)
@@ -359,7 +359,7 @@ func loadOrCreateAsymmetricKey() (interface{}, error) {
}
if !isExist {
err := func() error {
key, err := func() (interface{}, error) {
key, err := func() (any, error) {
switch {
case strings.HasPrefix(setting.OAuth2.JWTSigningAlgorithm, "RS"):
return rsa.GenerateKey(rand.Reader, 4096)

View File

@@ -41,7 +41,7 @@ type Token struct {
// ParseToken parses a signed jwt string
func ParseToken(jwtToken string, signingKey JWTSigningKey) (*Token, error) {
parsedToken, err := jwt.ParseWithClaims(jwtToken, &Token{}, func(token *jwt.Token) (interface{}, error) {
parsedToken, err := jwt.ParseWithClaims(jwtToken, &Token{}, func(token *jwt.Token) (any, error) {
if token.Method == nil || token.Method.Alg() != signingKey.SigningMethod().Alg() {
return nil, fmt.Errorf("unexpected signing algo: %v", token.Header["alg"])
}

View File

@@ -15,7 +15,7 @@ import (
// UserAssignmentWeb returns a middleware to handle context-user assignment for web routes
func UserAssignmentWeb() func(ctx *context.Context) {
return func(ctx *context.Context) {
errorFn := func(status int, title string, obj interface{}) {
errorFn := func(status int, title string, obj any) {
err, ok := obj.(error)
if !ok {
err = fmt.Errorf("%s", obj)
@@ -58,7 +58,7 @@ func UserAssignmentAPI() func(ctx *context.APIContext) {
}
}
func userAssignment(ctx *context.Base, doer *user_model.User, errCb func(int, string, interface{})) (contextUser *user_model.User) {
func userAssignment(ctx *context.Base, doer *user_model.User, errCb func(int, string, any)) (contextUser *user_model.User) {
username := ctx.Params(":username")
if doer != nil && doer.LowerName == strings.ToLower(username) {

View File

@@ -14,7 +14,7 @@ type Config interface {
IsEnabled() bool
DoRunAtStart() bool
GetSchedule() string
FormatMessage(locale translation.Locale, name, status, doer string, args ...interface{}) string
FormatMessage(locale translation.Locale, name, status, doer string, args ...any) string
DoNoticeOnSuccess() bool
}
@@ -68,8 +68,8 @@ func (b *BaseConfig) DoNoticeOnSuccess() bool {
// FormatMessage returns a message for the task
// Please note the `status` string will be concatenated with `admin.dashboard.cron.` and `admin.dashboard.task.` to provide locale messages. Similarly `name` will be composed with `admin.dashboard.` to provide the locale name for the task.
func (b *BaseConfig) FormatMessage(locale translation.Locale, name, status, doer string, args ...interface{}) string {
realArgs := make([]interface{}, 0, len(args)+2)
func (b *BaseConfig) FormatMessage(locale translation.Locale, name, status, doer string, args ...any) string {
realArgs := make([]any, 0, len(args)+2)
realArgs = append(realArgs, locale.Tr("admin.dashboard."+name))
if doer == "" {
realArgs = append(realArgs, "(Cron)")

View File

@@ -13,8 +13,8 @@ import (
// Store represents a thing that stores things
type Store interface {
Get(interface{}) interface{}
Set(interface{}, interface{}) error
Get(any) any
Set(any, any) error
Release() error
}

View File

@@ -375,7 +375,7 @@ func VerifyHandler(ctx *context.Context) {
writeStatus(ctx, status)
}
func decodeJSON(req *http.Request, v interface{}) error {
func decodeJSON(req *http.Request, v any) error {
defer req.Body.Close()
dec := json.NewDecoder(req.Body)
@@ -552,7 +552,7 @@ func handleLFSToken(ctx stdCtx.Context, tokenSHA string, target *repo_model.Repo
if !strings.Contains(tokenSHA, ".") {
return nil, nil
}
token, err := jwt.ParseWithClaims(tokenSHA, &Claims{}, func(t *jwt.Token) (interface{}, error) {
token, err := jwt.ParseWithClaims(tokenSHA, &Claims{}, func(t *jwt.Token) (any, error) {
if _, ok := t.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("unexpected signing method: %v", t.Header["alg"])
}

View File

@@ -205,7 +205,7 @@ loop:
if err := c.Store(
handledSet,
imap.FormatFlagsOp(imap.AddFlags, true),
[]interface{}{imap.DeletedFlag},
[]any{imap.DeletedFlag},
nil,
); err != nil {
return fmt.Errorf("imap store failed: %w", err)

View File

@@ -20,7 +20,7 @@ const (
)
// CreateReferencePayload creates data which GetReferenceFromPayload resolves to the reference again.
func CreateReferencePayload(reference interface{}) ([]byte, error) {
func CreateReferencePayload(reference any) ([]byte, error) {
var refType payloadReferenceType
var refID int64
@@ -44,7 +44,7 @@ func CreateReferencePayload(reference interface{}) ([]byte, error) {
}
// GetReferenceFromPayload resolves the reference from the payload
func GetReferenceFromPayload(ctx context.Context, payload []byte) (interface{}, error) {
func GetReferenceFromPayload(ctx context.Context, payload []byte) (any, error) {
if len(payload) < 1 {
return nil, util.NewInvalidArgumentErrorf("payload to small")
}

View File

@@ -67,7 +67,7 @@ func SendTestMail(email string) error {
// sendUserMail sends a mail to the user
func sendUserMail(language string, u *user_model.User, tpl base.TplName, code, subject, info string) {
locale := translation.NewLocale(language)
data := map[string]interface{}{
data := map[string]any{
"DisplayName": u.DisplayName(),
"ActiveCodeLives": timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, locale),
"ResetPwdCodeLives": timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, locale),
@@ -118,7 +118,7 @@ func SendActivateEmailMail(u *user_model.User, email *user_model.EmailAddress) {
return
}
locale := translation.NewLocale(u.Language)
data := map[string]interface{}{
data := map[string]any{
"DisplayName": u.DisplayName(),
"ActiveCodeLives": timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, locale),
"Code": u.GenerateEmailActivateCode(email.Email),
@@ -151,7 +151,7 @@ func SendRegisterNotifyMail(u *user_model.User) {
}
locale := translation.NewLocale(u.Language)
data := map[string]interface{}{
data := map[string]any{
"DisplayName": u.DisplayName(),
"Username": u.Name,
"Language": locale.Language(),
@@ -184,7 +184,7 @@ func SendCollaboratorMail(u, doer *user_model.User, repo *repo_model.Repository)
repoName := repo.FullName()
subject := locale.Tr("mail.repo.collaborator.added.subject", doer.DisplayName(), repoName)
data := map[string]interface{}{
data := map[string]any{
"Subject": subject,
"RepoName": repoName,
"Link": repo.HTMLURL(),
@@ -258,7 +258,7 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
}
locale := translation.NewLocale(lang)
mailMeta := map[string]interface{}{
mailMeta := map[string]any{
"FallbackSubject": fallback,
"Body": body,
"Link": link,

View File

@@ -68,7 +68,7 @@ func mailNewRelease(ctx context.Context, lang string, tos []string, rel *repo_mo
}
subject := locale.Tr("mail.release.new.subject", rel.TagName, rel.Repo.FullName())
mailMeta := map[string]interface{}{
mailMeta := map[string]any{
"Release": rel,
"Subject": subject,
"Language": locale.Language(),

View File

@@ -64,7 +64,7 @@ func sendRepoTransferNotifyMailPerLang(lang string, newOwner, doer *user_model.U
subject = locale.Tr("mail.repo.transfer.subject_to", doer.DisplayName(), repo.FullName(), destination)
}
data := map[string]interface{}{
data := map[string]any{
"Doer": doer,
"User": repo.Owner,
"Repo": repo.FullName(),

View File

@@ -34,7 +34,7 @@ func MailTeamInvite(ctx context.Context, inviter *user_model.User, team *org_mod
locale := translation.NewLocale(inviter.Language)
subject := locale.Tr("mail.team_invite.subject", inviter.DisplayName(), org.DisplayName())
mailMeta := map[string]interface{}{
mailMeta := map[string]any{
"Inviter": inviter,
"Organization": org,
"Team": team,

View File

@@ -127,7 +127,7 @@ func (d *CodebaseDownloader) FormatCloneURL(opts base.MigrateOptions, remoteAddr
return opts.CloneAddr, nil
}
func (d *CodebaseDownloader) callAPI(endpoint string, parameter map[string]string, result interface{}) error {
func (d *CodebaseDownloader) callAPI(endpoint string, parameter map[string]string, result any) error {
u, err := d.baseURL.Parse(endpoint)
if err != nil {
return err

View File

@@ -14,7 +14,7 @@ import (
)
// WarnAndNotice will log the provided message and send a repository notice
func WarnAndNotice(fmtStr string, args ...interface{}) {
func WarnAndNotice(fmtStr string, args ...any) {
log.Warn(fmtStr, args...)
if err := system_model.CreateRepositoryNotice(fmt.Sprintf(fmtStr, args...)); err != nil {
log.Error("create repository notice failed: ", err)

View File

@@ -112,7 +112,7 @@ func (g *RepositoryDumper) CreateRepo(repo *base.Repository, opts base.MigrateOp
}
defer f.Close()
bs, err := yaml.Marshal(map[string]interface{}{
bs, err := yaml.Marshal(map[string]any{
"name": repo.Name,
"owner": repo.Owner,
"description": repo.Description,
@@ -227,7 +227,7 @@ func (g *RepositoryDumper) CreateTopics(topics ...string) error {
}
defer f.Close()
bs, err := yaml.Marshal(map[string]interface{}{
bs, err := yaml.Marshal(map[string]any{
"topics": topics,
})
if err != nil {
@@ -380,7 +380,7 @@ func (g *RepositoryDumper) CreateIssues(issues ...*base.Issue) error {
return nil
}
func (g *RepositoryDumper) createItems(dir string, itemFiles map[int64]*os.File, itemsMap map[int64][]interface{}) error {
func (g *RepositoryDumper) createItems(dir string, itemFiles map[int64]*os.File, itemsMap map[int64][]any) error {
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
return err
}
@@ -394,7 +394,7 @@ func (g *RepositoryDumper) createItems(dir string, itemFiles map[int64]*os.File,
return nil
}
func (g *RepositoryDumper) encodeItems(number int64, items []interface{}, dir string, itemFiles map[int64]*os.File) error {
func (g *RepositoryDumper) encodeItems(number int64, items []any, dir string, itemFiles map[int64]*os.File) error {
itemFile := itemFiles[number]
if itemFile == nil {
var err error
@@ -413,7 +413,7 @@ func (g *RepositoryDumper) encodeItems(number int64, items []interface{}, dir st
// CreateComments creates comments of issues
func (g *RepositoryDumper) CreateComments(comments ...*base.Comment) error {
commentsMap := make(map[int64][]interface{}, len(comments))
commentsMap := make(map[int64][]any, len(comments))
for _, comment := range comments {
commentsMap[comment.IssueIndex] = append(commentsMap[comment.IssueIndex], comment)
}
@@ -621,7 +621,7 @@ func (g *RepositoryDumper) CreatePullRequests(prs ...*base.PullRequest) error {
// CreateReviews create pull request reviews
func (g *RepositoryDumper) CreateReviews(reviews ...*base.Review) error {
reviewsMap := make(map[int64][]interface{}, len(reviews))
reviewsMap := make(map[int64][]any, len(reviews))
for _, review := range reviews {
reviewsMap[review.IssueIndex] = append(reviewsMap[review.IssueIndex], review)
}

View File

@@ -121,7 +121,7 @@ func (d *OneDevDownloader) LogString() string {
return fmt.Sprintf("<OneDevDownloader %s [%d]/%s>", d.baseURL, d.repoID, d.repoName)
}
func (d *OneDevDownloader) callAPI(endpoint string, parameter map[string]string, result interface{}) error {
func (d *OneDevDownloader) callAPI(endpoint string, parameter map[string]string, result any) error {
u, err := d.baseURL.Parse(endpoint)
if err != nil {
return err
@@ -400,9 +400,9 @@ func (d *OneDevDownloader) GetComments(commentable base.Commentable) ([]*base.Co
}
rawChanges := make([]struct {
Date time.Time `json:"date"`
UserID int64 `json:"userId"`
Data map[string]interface{} `json:"data"`
Date time.Time `json:"date"`
UserID int64 `json:"userId"`
Data map[string]any `json:"data"`
}, 0, 100)
if context.IsPullRequest {

View File

@@ -41,7 +41,7 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
}
log.Trace("Doing: Update")
handler := func(idx int, bean interface{}) error {
handler := func(idx int, bean any) error {
var repo *repo_model.Repository
var mirrorType mirror_module.SyncType
var referenceID int64
@@ -91,7 +91,7 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
pullMirrorsRequested := 0
if pullLimit != 0 {
if err := repo_model.MirrorsIterate(pullLimit, func(idx int, bean interface{}) error {
if err := repo_model.MirrorsIterate(pullLimit, func(idx int, bean any) error {
if err := handler(idx, bean); err != nil {
return err
}
@@ -105,7 +105,7 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
pushMirrorsRequested := 0
if pushLimit != 0 {
if err := repo_model.PushMirrorsIterate(ctx, pushLimit, func(idx int, bean interface{}) error {
if err := repo_model.PushMirrorsIterate(ctx, pushLimit, func(idx int, bean any) error {
if err := handler(idx, bean); err != nil {
return err
}

View File

@@ -53,7 +53,7 @@ func ParseAuthorizationToken(req *http.Request) (int64, error) {
return 0, fmt.Errorf("split token failed")
}
token, err := jwt.ParseWithClaims(parts[1], &packageClaims{}, func(t *jwt.Token) (interface{}, error) {
token, err := jwt.ParseWithClaims(parts[1], &packageClaims{}, func(t *jwt.Token) (any, error) {
if _, ok := t.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("unexpected signing method: %v", t.Header["alg"])
}

View File

@@ -44,7 +44,7 @@ type PackageCreationInfo struct {
PackageInfo
SemverCompatible bool
Creator *user_model.User
Metadata interface{}
Metadata any
PackageProperties map[string]string
VersionProperties map[string]string
}

View File

@@ -40,9 +40,9 @@ func (ct *ContentType) String() string {
// GetContentsOrList gets the meta data of a file's contents (*ContentsResponse) if treePath not a tree
// directory, otherwise a listing of file contents ([]*ContentsResponse). Ref can be a branch, commit or tag
func GetContentsOrList(ctx context.Context, repo *repo_model.Repository, treePath, ref string) (interface{}, error) {
func GetContentsOrList(ctx context.Context, repo *repo_model.Repository, treePath, ref string) (any, error) {
if repo.IsEmpty {
return make([]interface{}, 0), nil
return make([]any, 0), nil
}
if ref == "" {
ref = repo.DefaultBranch

View File

@@ -121,7 +121,7 @@ func runMigrateTask(t *admin_model.Task) (err error) {
}
}()
t.Repo, err = migrations.MigrateRepository(ctx, t.Doer, t.Owner.Name, *opts, func(format string, args ...interface{}) {
t.Repo, err = migrations.MigrateRepository(ctx, t.Doer, t.Owner.Name, *opts, func(format string, args ...any) {
message := admin_model.TranslatableMessage{
Format: format,
Args: args,