aboutsummaryrefslogtreecommitdiff
path: root/routes/api/v1/repo/file.go
diff options
context:
space:
mode:
authorunknwon <u@gogs.io>2019-08-10 13:40:48 -0700
committerunknwon <u@gogs.io>2019-08-10 13:40:48 -0700
commitf1e0ebfe937213be2af4a3180fae9f43949de00e (patch)
tree3b462bd02b3c5d28099ca5e47e21370d8c02688a /routes/api/v1/repo/file.go
parentc7ba519af2f2d8e79077d2776cb34f8b61556471 (diff)
routes/api/v1: codemod
Diffstat (limited to 'routes/api/v1/repo/file.go')
-rw-r--r--routes/api/v1/repo/file.go26
1 files changed, 8 insertions, 18 deletions
diff --git a/routes/api/v1/repo/file.go b/routes/api/v1/repo/file.go
index 5afb1113..744db738 100644
--- a/routes/api/v1/repo/file.go
+++ b/routes/api/v1/repo/file.go
@@ -12,38 +12,32 @@ import (
"github.com/gogs/gogs/routes/repo"
)
-// https://github.com/gogs/go-gogs-client/wiki/Repositories-Contents#download-raw-content
func GetRawFile(c *context.APIContext) {
if !c.Repo.HasAccess() {
- c.Status(404)
+ c.NotFound()
return
}
if c.Repo.Repository.IsBare {
- c.Status(404)
+ c.NotFound()
return
}
blob, err := c.Repo.Commit.GetBlobByPath(c.Repo.TreePath)
if err != nil {
- if git.IsErrNotExist(err) {
- c.Status(404)
- } else {
- c.Error(500, "GetBlobByPath", err)
- }
+ c.NotFoundOrServerError("GetBlobByPath", git.IsErrNotExist, err)
return
}
if err = repo.ServeBlob(c.Context, blob); err != nil {
- c.Error(500, "ServeBlob", err)
+ c.ServerError("ServeBlob", err)
}
}
-// https://github.com/gogs/go-gogs-client/wiki/Repositories-Contents#download-archive
func GetArchive(c *context.APIContext) {
repoPath := models.RepoPath(c.Params(":username"), c.Params(":reponame"))
gitRepo, err := git.OpenRepository(repoPath)
if err != nil {
- c.Error(500, "OpenRepository", err)
+ c.ServerError("OpenRepository", err)
return
}
c.Repo.GitRepo = gitRepo
@@ -54,19 +48,15 @@ func GetArchive(c *context.APIContext) {
func GetEditorconfig(c *context.APIContext) {
ec, err := c.Repo.GetEditorconfig()
if err != nil {
- if git.IsErrNotExist(err) {
- c.Error(404, "GetEditorconfig", err)
- } else {
- c.Error(500, "GetEditorconfig", err)
- }
+ c.NotFoundOrServerError("GetEditorconfig", git.IsErrNotExist, err)
return
}
fileName := c.Params("filename")
def := ec.GetDefinitionForFilename(fileName)
if def == nil {
- c.Error(404, "GetDefinitionForFilename", err)
+ c.NotFound()
return
}
- c.JSON(200, def)
+ c.JSONSuccess(def)
}