mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Refactor names (#31405)
This PR only does "renaming": * `Route` should be `Router` (and chi router is also called "router") * `Params` should be `PathParam` (to distingush it from URL query param, and to match `FormString`) * Use lower case for private functions to avoid exposing or abusing
This commit is contained in:
@@ -49,7 +49,7 @@ func CreateOrUpdateSecret(ctx *context.APIContext) {
|
||||
|
||||
opt := web.GetForm(ctx).(*api.CreateOrUpdateSecretOption)
|
||||
|
||||
_, created, err := secret_service.CreateOrUpdateSecret(ctx, ctx.Doer.ID, 0, ctx.Params("secretname"), opt.Data)
|
||||
_, created, err := secret_service.CreateOrUpdateSecret(ctx, ctx.Doer.ID, 0, ctx.PathParam("secretname"), opt.Data)
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrInvalidArgument) {
|
||||
ctx.Error(http.StatusBadRequest, "CreateOrUpdateSecret", err)
|
||||
@@ -91,7 +91,7 @@ func DeleteSecret(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
err := secret_service.DeleteSecretByName(ctx, ctx.Doer.ID, 0, ctx.Params("secretname"))
|
||||
err := secret_service.DeleteSecretByName(ctx, ctx.Doer.ID, 0, ctx.PathParam("secretname"))
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrInvalidArgument) {
|
||||
ctx.Error(http.StatusBadRequest, "DeleteSecret", err)
|
||||
@@ -138,7 +138,7 @@ func CreateVariable(ctx *context.APIContext) {
|
||||
opt := web.GetForm(ctx).(*api.CreateVariableOption)
|
||||
|
||||
ownerID := ctx.Doer.ID
|
||||
variableName := ctx.Params("variablename")
|
||||
variableName := ctx.PathParam("variablename")
|
||||
|
||||
v, err := actions_service.GetVariable(ctx, actions_model.FindVariablesOpts{
|
||||
OwnerID: ownerID,
|
||||
@@ -198,7 +198,7 @@ func UpdateVariable(ctx *context.APIContext) {
|
||||
|
||||
v, err := actions_service.GetVariable(ctx, actions_model.FindVariablesOpts{
|
||||
OwnerID: ctx.Doer.ID,
|
||||
Name: ctx.Params("variablename"),
|
||||
Name: ctx.PathParam("variablename"),
|
||||
})
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrNotExist) {
|
||||
@@ -210,7 +210,7 @@ func UpdateVariable(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
if opt.Name == "" {
|
||||
opt.Name = ctx.Params("variablename")
|
||||
opt.Name = ctx.PathParam("variablename")
|
||||
}
|
||||
if _, err := actions_service.UpdateVariable(ctx, v.ID, opt.Name, opt.Value); err != nil {
|
||||
if errors.Is(err, util.ErrInvalidArgument) {
|
||||
@@ -247,7 +247,7 @@ func DeleteVariable(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
if err := actions_service.DeleteVariableByName(ctx, ctx.Doer.ID, 0, ctx.Params("variablename")); err != nil {
|
||||
if err := actions_service.DeleteVariableByName(ctx, ctx.Doer.ID, 0, ctx.PathParam("variablename")); err != nil {
|
||||
if errors.Is(err, util.ErrInvalidArgument) {
|
||||
ctx.Error(http.StatusBadRequest, "DeleteVariableByName", err)
|
||||
} else if errors.Is(err, util.ErrNotExist) {
|
||||
@@ -284,7 +284,7 @@ func GetVariable(ctx *context.APIContext) {
|
||||
|
||||
v, err := actions_service.GetVariable(ctx, actions_model.FindVariablesOpts{
|
||||
OwnerID: ctx.Doer.ID,
|
||||
Name: ctx.Params("variablename"),
|
||||
Name: ctx.PathParam("variablename"),
|
||||
})
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrNotExist) {
|
||||
|
@@ -160,7 +160,7 @@ func DeleteAccessToken(ctx *context.APIContext) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/error"
|
||||
|
||||
token := ctx.Params(":id")
|
||||
token := ctx.PathParam(":id")
|
||||
tokenID, _ := strconv.ParseInt(token, 0, 64)
|
||||
|
||||
if tokenID == 0 {
|
||||
@@ -300,7 +300,7 @@ func DeleteOauth2Application(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/empty"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
appID := ctx.ParamsInt64(":id")
|
||||
appID := ctx.PathParamInt64(":id")
|
||||
if err := auth_model.DeleteOAuth2Application(ctx, appID, ctx.Doer.ID); err != nil {
|
||||
if auth_model.IsErrOAuthApplicationNotFound(err) {
|
||||
ctx.NotFound()
|
||||
@@ -332,7 +332,7 @@ func GetOauth2Application(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/OAuth2Application"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
appID := ctx.ParamsInt64(":id")
|
||||
appID := ctx.PathParamInt64(":id")
|
||||
app, err := auth_model.GetOAuth2ApplicationByID(ctx, appID)
|
||||
if err != nil {
|
||||
if auth_model.IsErrOauthClientIDInvalid(err) || auth_model.IsErrOAuthApplicationNotFound(err) {
|
||||
@@ -376,7 +376,7 @@ func UpdateOauth2Application(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/OAuth2Application"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
appID := ctx.ParamsInt64(":id")
|
||||
appID := ctx.PathParamInt64(":id")
|
||||
|
||||
data := web.GetForm(ctx).(*api.CreateOAuth2ApplicationOptions)
|
||||
|
||||
|
@@ -116,7 +116,7 @@ func GetGPGKey(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
key, err := asymkey_model.GetGPGKeyForUserByID(ctx, ctx.Doer.ID, ctx.ParamsInt64(":id"))
|
||||
key, err := asymkey_model.GetGPGKeyForUserByID(ctx, ctx.Doer.ID, ctx.PathParamInt64(":id"))
|
||||
if err != nil {
|
||||
if asymkey_model.IsErrGPGKeyNotExist(err) {
|
||||
ctx.NotFound()
|
||||
@@ -280,7 +280,7 @@ func DeleteGPGKey(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := asymkey_model.DeleteGPGKey(ctx, ctx.Doer, ctx.ParamsInt64(":id")); err != nil {
|
||||
if err := asymkey_model.DeleteGPGKey(ctx, ctx.Doer, ctx.PathParamInt64(":id")); err != nil {
|
||||
if asymkey_model.IsErrGPGKeyAccessDenied(err) {
|
||||
ctx.Error(http.StatusForbidden, "", "You do not have access to this key")
|
||||
} else {
|
||||
|
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
// GetUserByParamsName get user by name
|
||||
func GetUserByParamsName(ctx *context.APIContext, name string) *user_model.User {
|
||||
username := ctx.Params(name)
|
||||
username := ctx.PathParam(name)
|
||||
user, err := user_model.GetUserByName(ctx, username)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
|
@@ -57,7 +57,7 @@ func GetHook(ctx *context.APIContext) {
|
||||
// "200":
|
||||
// "$ref": "#/responses/Hook"
|
||||
|
||||
hook, err := utils.GetOwnerHook(ctx, ctx.Doer.ID, ctx.ParamsInt64("id"))
|
||||
hook, err := utils.GetOwnerHook(ctx, ctx.Doer.ID, ctx.PathParamInt64("id"))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -129,7 +129,7 @@ func EditHook(ctx *context.APIContext) {
|
||||
ctx,
|
||||
ctx.Doer,
|
||||
web.GetForm(ctx).(*api.EditHookOption),
|
||||
ctx.ParamsInt64("id"),
|
||||
ctx.PathParamInt64("id"),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -154,6 +154,6 @@ func DeleteHook(ctx *context.APIContext) {
|
||||
utils.DeleteOwnerHook(
|
||||
ctx,
|
||||
ctx.Doer,
|
||||
ctx.ParamsInt64("id"),
|
||||
ctx.PathParamInt64("id"),
|
||||
)
|
||||
}
|
||||
|
@@ -55,7 +55,7 @@ func listPublicKeys(ctx *context.APIContext, user *user_model.User) {
|
||||
var count int
|
||||
|
||||
fingerprint := ctx.FormString("fingerprint")
|
||||
username := ctx.Params("username")
|
||||
username := ctx.PathParam("username")
|
||||
|
||||
if fingerprint != "" {
|
||||
var userID int64 // Unrestricted
|
||||
@@ -179,7 +179,7 @@ func GetPublicKey(ctx *context.APIContext) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
key, err := asymkey_model.GetPublicKeyByID(ctx, ctx.ParamsInt64(":id"))
|
||||
key, err := asymkey_model.GetPublicKeyByID(ctx, ctx.PathParamInt64(":id"))
|
||||
if err != nil {
|
||||
if asymkey_model.IsErrKeyNotExist(err) {
|
||||
ctx.NotFound()
|
||||
@@ -274,7 +274,7 @@ func DeletePublicKey(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
id := ctx.ParamsInt64(":id")
|
||||
id := ctx.PathParamInt64(":id")
|
||||
externallyManaged, err := asymkey_model.PublicKeyIsExternallyManaged(ctx, id)
|
||||
if err != nil {
|
||||
if asymkey_model.IsErrKeyNotExist(err) {
|
||||
|
@@ -113,7 +113,7 @@ func GetInfo(ctx *context.APIContext) {
|
||||
|
||||
if !user_model.IsUserVisibleToViewer(ctx, ctx.ContextUser, ctx.Doer) {
|
||||
// fake ErrUserNotExist error message to not leak information about existence
|
||||
ctx.NotFound("GetUserByName", user_model.ErrUserNotExist{Name: ctx.Params(":username")})
|
||||
ctx.NotFound("GetUserByName", user_model.ErrUserNotExist{Name: ctx.PathParam(":username")})
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, convert.ToUser(ctx, ctx.ContextUser, ctx.Doer))
|
||||
|
Reference in New Issue
Block a user