diff options
Diffstat (limited to 'routers/api')
27 files changed, 49 insertions, 49 deletions
diff --git a/routers/api/actions/runner/utils.go b/routers/api/actions/runner/utils.go index 3370355f15..834a8c4400 100644 --- a/routers/api/actions/runner/utils.go +++ b/routers/api/actions/runner/utils.go @@ -116,7 +116,7 @@ func getVariablesOfTask(ctx context.Context, task *actions_model.ActionTask) map } func generateTaskContext(t *actions_model.ActionTask) *structpb.Struct { - event := map[string]interface{}{} + event := map[string]any{} _ = json.Unmarshal([]byte(t.Job.Run.EventPayload), &event) // TriggerEvent is added in https://github.com/go-gitea/gitea/pull/25229 @@ -136,7 +136,7 @@ func generateTaskContext(t *actions_model.ActionTask) *structpb.Struct { refName := git.RefName(t.Job.Run.Ref) - taskContext, err := structpb.NewStruct(map[string]interface{}{ + taskContext, err := structpb.NewStruct(map[string]any{ // standard contexts, see https://docs.github.com/en/actions/learn-github-actions/contexts#github-context "action": "", // string, The name of the action currently running, or the id of a step. GitHub removes special characters, and uses the name __run when the current step runs a script without an id. If you use the same action more than once in the same job, the name will include a suffix with the sequence number with underscore before it. For example, the first script you run will have the name __run, and the second script will be named __run_2. Similarly, the second invocation of actions/checkout will be actionscheckout2. "action_path": "", // string, The path where an action is located. This property is only supported in composite actions. You can use this path to access files located in the same repository as the action. diff --git a/routers/api/packages/alpine/alpine.go b/routers/api/packages/alpine/alpine.go index e357e9cb9b..51a5c784e0 100644 --- a/routers/api/packages/alpine/alpine.go +++ b/routers/api/packages/alpine/alpine.go @@ -24,7 +24,7 @@ import ( alpine_service "code.gitea.io/gitea/services/packages/alpine" ) -func apiError(ctx *context.Context, status int, obj interface{}) { +func apiError(ctx *context.Context, status int, obj any) { helper.LogAndProcessError(ctx, status, obj, func(message string) { ctx.PlainText(status, message) }) diff --git a/routers/api/packages/cargo/cargo.go b/routers/api/packages/cargo/cargo.go index a0a0cea923..a2e835df57 100644 --- a/routers/api/packages/cargo/cargo.go +++ b/routers/api/packages/cargo/cargo.go @@ -33,7 +33,7 @@ type StatusMessage struct { Message string `json:"detail"` } -func apiError(ctx *context.Context, status int, obj interface{}) { +func apiError(ctx *context.Context, status int, obj any) { helper.LogAndProcessError(ctx, status, obj, func(message string) { ctx.JSON(status, StatusResponse{ OK: false, diff --git a/routers/api/packages/chef/chef.go b/routers/api/packages/chef/chef.go index 355f01a8ff..908f9fc4be 100644 --- a/routers/api/packages/chef/chef.go +++ b/routers/api/packages/chef/chef.go @@ -24,7 +24,7 @@ import ( packages_service "code.gitea.io/gitea/services/packages" ) -func apiError(ctx *context.Context, status int, obj interface{}) { +func apiError(ctx *context.Context, status int, obj any) { type Error struct { ErrorMessages []string `json:"error_messages"` } diff --git a/routers/api/packages/composer/composer.go b/routers/api/packages/composer/composer.go index 06b4f4652a..bf5bda743f 100644 --- a/routers/api/packages/composer/composer.go +++ b/routers/api/packages/composer/composer.go @@ -26,7 +26,7 @@ import ( "github.com/hashicorp/go-version" ) -func apiError(ctx *context.Context, status int, obj interface{}) { +func apiError(ctx *context.Context, status int, obj any) { helper.LogAndProcessError(ctx, status, obj, func(message string) { type Error struct { Status int `json:"status"` diff --git a/routers/api/packages/conan/conan.go b/routers/api/packages/conan/conan.go index 616e57b365..6e1727fd76 100644 --- a/routers/api/packages/conan/conan.go +++ b/routers/api/packages/conan/conan.go @@ -47,7 +47,7 @@ var ( ) ) -func jsonResponse(ctx *context.Context, status int, obj interface{}) { +func jsonResponse(ctx *context.Context, status int, obj any) { // https://github.com/conan-io/conan/issues/6613 ctx.Resp.Header().Set("Content-Type", "application/json") ctx.Status(status) @@ -56,7 +56,7 @@ func jsonResponse(ctx *context.Context, status int, obj interface{}) { } } -func apiError(ctx *context.Context, status int, obj interface{}) { +func apiError(ctx *context.Context, status int, obj any) { helper.LogAndProcessError(ctx, status, obj, func(message string) { jsonResponse(ctx, status, map[string]string{ "message": message, @@ -796,13 +796,13 @@ func listRevisionFiles(ctx *context.Context, fileKey string) { return } - files := make(map[string]interface{}) + files := make(map[string]any) for _, pf := range pfs { files[pf.Name] = nil } type FileList struct { - Files map[string]interface{} `json:"files"` + Files map[string]any `json:"files"` } jsonResponse(ctx, http.StatusOK, &FileList{ diff --git a/routers/api/packages/conda/conda.go b/routers/api/packages/conda/conda.go index 9c5edd548b..0bf0fc1f62 100644 --- a/routers/api/packages/conda/conda.go +++ b/routers/api/packages/conda/conda.go @@ -24,7 +24,7 @@ import ( "github.com/dsnet/compress/bzip2" ) -func apiError(ctx *context.Context, status int, obj interface{}) { +func apiError(ctx *context.Context, status int, obj any) { helper.LogAndProcessError(ctx, status, obj, func(message string) { ctx.JSON(status, struct { Reason string `json:"reason"` diff --git a/routers/api/packages/container/container.go b/routers/api/packages/container/container.go index 07cf387dde..126be43cdd 100644 --- a/routers/api/packages/container/container.go +++ b/routers/api/packages/container/container.go @@ -75,7 +75,7 @@ func setResponseHeaders(resp http.ResponseWriter, h *containerHeaders) { resp.WriteHeader(h.Status) } -func jsonResponse(ctx *context.Context, status int, obj interface{}) { +func jsonResponse(ctx *context.Context, status int, obj any) { setResponseHeaders(ctx.Resp, &containerHeaders{ Status: status, ContentType: "application/json", diff --git a/routers/api/packages/cran/cran.go b/routers/api/packages/cran/cran.go index 76de3b7879..0ef6eff88d 100644 --- a/routers/api/packages/cran/cran.go +++ b/routers/api/packages/cran/cran.go @@ -21,7 +21,7 @@ import ( packages_service "code.gitea.io/gitea/services/packages" ) -func apiError(ctx *context.Context, status int, obj interface{}) { +func apiError(ctx *context.Context, status int, obj any) { helper.LogAndProcessError(ctx, status, obj, func(message string) { ctx.PlainText(status, message) }) diff --git a/routers/api/packages/debian/debian.go b/routers/api/packages/debian/debian.go index 676816cf72..f7270e0ae0 100644 --- a/routers/api/packages/debian/debian.go +++ b/routers/api/packages/debian/debian.go @@ -23,7 +23,7 @@ import ( debian_service "code.gitea.io/gitea/services/packages/debian" ) -func apiError(ctx *context.Context, status int, obj interface{}) { +func apiError(ctx *context.Context, status int, obj any) { helper.LogAndProcessError(ctx, status, obj, func(message string) { ctx.PlainText(status, message) }) diff --git a/routers/api/packages/generic/generic.go b/routers/api/packages/generic/generic.go index 7cd1d1a5be..c5866ef9c3 100644 --- a/routers/api/packages/generic/generic.go +++ b/routers/api/packages/generic/generic.go @@ -22,7 +22,7 @@ var ( filenameRegex = packageNameRegex ) -func apiError(ctx *context.Context, status int, obj interface{}) { +func apiError(ctx *context.Context, status int, obj any) { helper.LogAndProcessError(ctx, status, obj, func(message string) { ctx.PlainText(status, message) }) diff --git a/routers/api/packages/goproxy/goproxy.go b/routers/api/packages/goproxy/goproxy.go index 350d2a3895..bacdc4ec62 100644 --- a/routers/api/packages/goproxy/goproxy.go +++ b/routers/api/packages/goproxy/goproxy.go @@ -20,7 +20,7 @@ import ( packages_service "code.gitea.io/gitea/services/packages" ) -func apiError(ctx *context.Context, status int, obj interface{}) { +func apiError(ctx *context.Context, status int, obj any) { helper.LogAndProcessError(ctx, status, obj, func(message string) { ctx.PlainText(status, message) }) diff --git a/routers/api/packages/helm/helm.go b/routers/api/packages/helm/helm.go index b50059951d..9097adf29e 100644 --- a/routers/api/packages/helm/helm.go +++ b/routers/api/packages/helm/helm.go @@ -26,7 +26,7 @@ import ( "gopkg.in/yaml.v3" ) -func apiError(ctx *context.Context, status int, obj interface{}) { +func apiError(ctx *context.Context, status int, obj any) { helper.LogAndProcessError(ctx, status, obj, func(message string) { type Error struct { Error string `json:"error"` diff --git a/routers/api/packages/helper/helper.go b/routers/api/packages/helper/helper.go index 3dec07f48a..aadb10376c 100644 --- a/routers/api/packages/helper/helper.go +++ b/routers/api/packages/helper/helper.go @@ -17,7 +17,7 @@ import ( // LogAndProcessError logs an error and calls a custom callback with the processed error message. // If the error is an InternalServerError the message is stripped if the user is not an admin. -func LogAndProcessError(ctx *context.Context, status int, obj interface{}, cb func(string)) { +func LogAndProcessError(ctx *context.Context, status int, obj any, cb func(string)) { var message string if err, ok := obj.(error); ok { message = err.Error() diff --git a/routers/api/packages/maven/maven.go b/routers/api/packages/maven/maven.go index 215cfa7e1f..84e3324367 100644 --- a/routers/api/packages/maven/maven.go +++ b/routers/api/packages/maven/maven.go @@ -47,7 +47,7 @@ var ( illegalCharacters = regexp.MustCompile(`[\\/:"<>|?\*]`) ) -func apiError(ctx *context.Context, status int, obj interface{}) { +func apiError(ctx *context.Context, status int, obj any) { helper.LogAndProcessError(ctx, status, obj, func(message string) { ctx.PlainText(status, message) }) diff --git a/routers/api/packages/npm/npm.go b/routers/api/packages/npm/npm.go index 77a820d27c..3616211d61 100644 --- a/routers/api/packages/npm/npm.go +++ b/routers/api/packages/npm/npm.go @@ -30,7 +30,7 @@ import ( // errInvalidTagName indicates an invalid tag name var errInvalidTagName = errors.New("The tag name is invalid") -func apiError(ctx *context.Context, status int, obj interface{}) { +func apiError(ctx *context.Context, status int, obj any) { helper.LogAndProcessError(ctx, status, obj, func(message string) { ctx.JSON(status, map[string]string{ "error": message, diff --git a/routers/api/packages/nuget/nuget.go b/routers/api/packages/nuget/nuget.go index 167776a383..edeba19b3b 100644 --- a/routers/api/packages/nuget/nuget.go +++ b/routers/api/packages/nuget/nuget.go @@ -25,7 +25,7 @@ import ( packages_service "code.gitea.io/gitea/services/packages" ) -func apiError(ctx *context.Context, status int, obj interface{}) { +func apiError(ctx *context.Context, status int, obj any) { helper.LogAndProcessError(ctx, status, obj, func(message string) { ctx.JSON(status, map[string]string{ "Message": message, @@ -33,7 +33,7 @@ func apiError(ctx *context.Context, status int, obj interface{}) { }) } -func xmlResponse(ctx *context.Context, status int, obj interface{}) { +func xmlResponse(ctx *context.Context, status int, obj any) { ctx.Resp.Header().Set("Content-Type", "application/atom+xml; charset=utf-8") ctx.Resp.WriteHeader(status) if _, err := ctx.Resp.Write([]byte(xml.Header)); err != nil { diff --git a/routers/api/packages/pub/pub.go b/routers/api/packages/pub/pub.go index 26fcd53c4c..ef07836b88 100644 --- a/routers/api/packages/pub/pub.go +++ b/routers/api/packages/pub/pub.go @@ -25,7 +25,7 @@ import ( packages_service "code.gitea.io/gitea/services/packages" ) -func jsonResponse(ctx *context.Context, status int, obj interface{}) { +func jsonResponse(ctx *context.Context, status int, obj any) { resp := ctx.Resp resp.Header().Set("Content-Type", "application/vnd.pub.v2+json") resp.WriteHeader(status) @@ -34,7 +34,7 @@ func jsonResponse(ctx *context.Context, status int, obj interface{}) { } } -func apiError(ctx *context.Context, status int, obj interface{}) { +func apiError(ctx *context.Context, status int, obj any) { type Error struct { Code string `json:"code"` Message string `json:"message"` @@ -60,10 +60,10 @@ type packageVersions struct { } type versionMetadata struct { - Version string `json:"version"` - ArchiveURL string `json:"archive_url"` - Published time.Time `json:"published"` - Pubspec interface{} `json:"pubspec,omitempty"` + Version string `json:"version"` + ArchiveURL string `json:"archive_url"` + Published time.Time `json:"published"` + Pubspec any `json:"pubspec,omitempty"` } func packageDescriptorToMetadata(baseURL string, pd *packages_model.PackageDescriptor) *versionMetadata { diff --git a/routers/api/packages/pypi/pypi.go b/routers/api/packages/pypi/pypi.go index 3ae5470ce8..d97b894bbe 100644 --- a/routers/api/packages/pypi/pypi.go +++ b/routers/api/packages/pypi/pypi.go @@ -37,7 +37,7 @@ var versionMatcher = regexp.MustCompile(`\Av?` + `(?:\+[a-z0-9]+(?:[-_\.][a-z0-9]+)*)?` + // local version `\z`) -func apiError(ctx *context.Context, status int, obj interface{}) { +func apiError(ctx *context.Context, status int, obj any) { helper.LogAndProcessError(ctx, status, obj, func(message string) { ctx.PlainText(status, message) }) diff --git a/routers/api/packages/rpm/rpm.go b/routers/api/packages/rpm/rpm.go index b4c62e2251..930b20208a 100644 --- a/routers/api/packages/rpm/rpm.go +++ b/routers/api/packages/rpm/rpm.go @@ -25,7 +25,7 @@ import ( rpm_service "code.gitea.io/gitea/services/packages/rpm" ) -func apiError(ctx *context.Context, status int, obj interface{}) { +func apiError(ctx *context.Context, status int, obj any) { helper.LogAndProcessError(ctx, status, obj, func(message string) { ctx.PlainText(status, message) }) diff --git a/routers/api/packages/rubygems/rubygems.go b/routers/api/packages/rubygems/rubygems.go index fd5be9730b..88d70f10bd 100644 --- a/routers/api/packages/rubygems/rubygems.go +++ b/routers/api/packages/rubygems/rubygems.go @@ -21,7 +21,7 @@ import ( packages_service "code.gitea.io/gitea/services/packages" ) -func apiError(ctx *context.Context, status int, obj interface{}) { +func apiError(ctx *context.Context, status int, obj any) { helper.LogAndProcessError(ctx, status, obj, func(message string) { ctx.PlainText(status, message) }) @@ -65,9 +65,9 @@ func enumeratePackages(ctx *context.Context, filename string, pvs []*packages_mo return } - specs := make([]interface{}, 0, len(pds)) + specs := make([]any, 0, len(pds)) for _, p := range pds { - specs = append(specs, []interface{}{ + specs = append(specs, []any{ p.Package.Name, &rubygems_module.RubyUserMarshal{ Name: "Gem::Version", @@ -129,7 +129,7 @@ func ServePackageSpecification(ctx *context.Context) { // create a Ruby Gem::Specification object spec := &rubygems_module.RubyUserDef{ Name: "Gem::Specification", - Value: []interface{}{ + Value: []any{ "3.2.3", // @rubygems_version 4, // @specification_version, pd.Package.Name, @@ -142,7 +142,7 @@ func ServePackageSpecification(ctx *context.Context) { nil, // @required_ruby_version nil, // @required_rubygems_version metadata.Platform, // @original_platform - []interface{}{}, // @dependencies + []any{}, // @dependencies nil, // rubyforge_project "", // @email metadata.Authors, diff --git a/routers/api/packages/swift/swift.go b/routers/api/packages/swift/swift.go index 263235a0c5..bd4b8095c2 100644 --- a/routers/api/packages/swift/swift.go +++ b/routers/api/packages/swift/swift.go @@ -69,7 +69,7 @@ func setResponseHeaders(resp http.ResponseWriter, h *headers) { } // https://github.com/apple/swift-package-manager/blob/main/Documentation/Registry.md#33-error-handling -func apiError(ctx *context.Context, status int, obj interface{}) { +func apiError(ctx *context.Context, status int, obj any) { // https://www.rfc-editor.org/rfc/rfc7807 type Problem struct { Status int `json:"status"` diff --git a/routers/api/packages/vagrant/vagrant.go b/routers/api/packages/vagrant/vagrant.go index 0decb2c023..9fe7ab56f6 100644 --- a/routers/api/packages/vagrant/vagrant.go +++ b/routers/api/packages/vagrant/vagrant.go @@ -22,7 +22,7 @@ import ( "github.com/hashicorp/go-version" ) -func apiError(ctx *context.Context, status int, obj interface{}) { +func apiError(ctx *context.Context, status int, obj any) { helper.LogAndProcessError(ctx, status, obj, func(message string) { ctx.JSON(status, struct { Errors []string `json:"errors"` diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index 1aaefacdd5..0e11acc901 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -792,7 +792,7 @@ func SearchTeam(ctx *context.APIContext) { teams, maxResults, err := organization.SearchTeam(opts) if err != nil { log.Error("SearchTeam failed: %v", err) - ctx.JSON(http.StatusInternalServerError, map[string]interface{}{ + ctx.JSON(http.StatusInternalServerError, map[string]any{ "ok": false, "error": "SearchTeam internal failure", }) @@ -807,7 +807,7 @@ func SearchTeam(ctx *context.APIContext) { ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) ctx.SetTotalCountHeader(maxResults) - ctx.JSON(http.StatusOK, map[string]interface{}{ + ctx.JSON(http.StatusOK, map[string]any{ "ok": true, "data": apiTeams, }) diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index a9f8b5b7e7..d9424d9e76 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -378,7 +378,7 @@ func Generate(ctx *context.APIContext) { ctxUser, err = user_model.GetUserByName(ctx, form.Owner) if err != nil { if user_model.IsErrUserNotExist(err) { - ctx.JSON(http.StatusNotFound, map[string]interface{}{ + ctx.JSON(http.StatusNotFound, map[string]any{ "error": "request owner `" + form.Owner + "` does not exist", }) return diff --git a/routers/api/v1/repo/topic.go b/routers/api/v1/repo/topic.go index 7d27fe7d25..8bf3012d48 100644 --- a/routers/api/v1/repo/topic.go +++ b/routers/api/v1/repo/topic.go @@ -63,7 +63,7 @@ func ListTopics(ctx *context.APIContext) { } ctx.SetTotalCountHeader(total) - ctx.JSON(http.StatusOK, map[string]interface{}{ + ctx.JSON(http.StatusOK, map[string]any{ "topics": topicNames, }) } @@ -101,7 +101,7 @@ func UpdateTopics(ctx *context.APIContext) { validTopics, invalidTopics := repo_model.SanitizeAndValidateTopics(topicNames) if len(validTopics) > 25 { - ctx.JSON(http.StatusUnprocessableEntity, map[string]interface{}{ + ctx.JSON(http.StatusUnprocessableEntity, map[string]any{ "invalidTopics": nil, "message": "Exceeding maximum number of topics per repo", }) @@ -109,7 +109,7 @@ func UpdateTopics(ctx *context.APIContext) { } if len(invalidTopics) > 0 { - ctx.JSON(http.StatusUnprocessableEntity, map[string]interface{}{ + ctx.JSON(http.StatusUnprocessableEntity, map[string]any{ "invalidTopics": invalidTopics, "message": "Topic names are invalid", }) @@ -158,7 +158,7 @@ func AddTopic(ctx *context.APIContext) { topicName := strings.TrimSpace(strings.ToLower(ctx.Params(":topic"))) if !repo_model.ValidateTopic(topicName) { - ctx.JSON(http.StatusUnprocessableEntity, map[string]interface{}{ + ctx.JSON(http.StatusUnprocessableEntity, map[string]any{ "invalidTopics": topicName, "message": "Topic name is invalid", }) @@ -175,7 +175,7 @@ func AddTopic(ctx *context.APIContext) { return } if count >= 25 { - ctx.JSON(http.StatusUnprocessableEntity, map[string]interface{}{ + ctx.JSON(http.StatusUnprocessableEntity, map[string]any{ "message": "Exceeding maximum allowed topics per repo.", }) return @@ -223,7 +223,7 @@ func DeleteTopic(ctx *context.APIContext) { topicName := strings.TrimSpace(strings.ToLower(ctx.Params(":topic"))) if !repo_model.ValidateTopic(topicName) { - ctx.JSON(http.StatusUnprocessableEntity, map[string]interface{}{ + ctx.JSON(http.StatusUnprocessableEntity, map[string]any{ "invalidTopics": topicName, "message": "Topic name is invalid", }) @@ -289,7 +289,7 @@ func TopicSearch(ctx *context.APIContext) { } ctx.SetTotalCountHeader(total) - ctx.JSON(http.StatusOK, map[string]interface{}{ + ctx.JSON(http.StatusOK, map[string]any{ "topics": topicResponses, }) } diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go index 314116962b..2a2361be67 100644 --- a/routers/api/v1/user/user.go +++ b/routers/api/v1/user/user.go @@ -62,7 +62,7 @@ func Search(ctx *context.APIContext) { ListOptions: listOptions, }) if err != nil { - ctx.JSON(http.StatusInternalServerError, map[string]interface{}{ + ctx.JSON(http.StatusInternalServerError, map[string]any{ "ok": false, "error": err.Error(), }) @@ -72,7 +72,7 @@ func Search(ctx *context.APIContext) { ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) ctx.SetTotalCountHeader(maxResults) - ctx.JSON(http.StatusOK, map[string]interface{}{ + ctx.JSON(http.StatusOK, map[string]any{ "ok": true, "data": convert.ToUsers(ctx, ctx.Doer, users), }) |