8
8
"encoding/gob"
9
9
"fmt"
10
10
"net/http"
11
- "net/url"
12
11
"os"
13
12
"path"
14
13
"strings"
@@ -24,7 +23,6 @@ import (
24
23
"code.gitea.io/gitea/modules/setting"
25
24
"code.gitea.io/gitea/modules/storage"
26
25
"code.gitea.io/gitea/modules/templates"
27
- "code.gitea.io/gitea/modules/util"
28
26
"code.gitea.io/gitea/modules/validation"
29
27
"code.gitea.io/gitea/modules/web"
30
28
"code.gitea.io/gitea/routers"
@@ -51,7 +49,6 @@ import (
51
49
"github.com/go-chi/cors"
52
50
"github.com/prometheus/client_golang/prometheus"
53
51
"github.com/tstranex/u2f"
54
- "github.com/unknwon/com"
55
52
)
56
53
57
54
const (
@@ -190,6 +187,7 @@ func WebRoutes() *web.Route {
190
187
ctx .Data ["UnitPullsGlobalDisabled" ] = models .UnitTypePullRequests .UnitGlobalDisabled ()
191
188
ctx .Data ["UnitProjectsGlobalDisabled" ] = models .UnitTypeProjects .UnitGlobalDisabled ()
192
189
})
190
+ r .Use (goGet )
193
191
194
192
// for health check
195
193
r .Head ("/" , func (w http.ResponseWriter , req * http.Request ) {
@@ -229,67 +227,6 @@ func WebRoutes() *web.Route {
229
227
return r
230
228
}
231
229
232
- func goGet (ctx * context.Context ) {
233
- if ctx .Query ("go-get" ) != "1" {
234
- return
235
- }
236
-
237
- // Quick responses appropriate go-get meta with status 200
238
- // regardless of if user have access to the repository,
239
- // or the repository does not exist at all.
240
- // This is particular a workaround for "go get" command which does not respect
241
- // .netrc file.
242
-
243
- ownerName := ctx .Params (":username" )
244
- repoName := ctx .Params (":reponame" )
245
- trimmedRepoName := strings .TrimSuffix (repoName , ".git" )
246
-
247
- if ownerName == "" || trimmedRepoName == "" {
248
- _ , _ = ctx .Write ([]byte (`<!doctype html>
249
- <html>
250
- <body>
251
- invalid import path
252
- </body>
253
- </html>
254
- ` ))
255
- ctx .Status (400 )
256
- return
257
- }
258
- branchName := setting .Repository .DefaultBranch
259
-
260
- repo , err := models .GetRepositoryByOwnerAndName (ownerName , repoName )
261
- if err == nil && len (repo .DefaultBranch ) > 0 {
262
- branchName = repo .DefaultBranch
263
- }
264
- prefix := setting .AppURL + path .Join (url .PathEscape (ownerName ), url .PathEscape (repoName ), "src" , "branch" , util .PathEscapeSegments (branchName ))
265
-
266
- appURL , _ := url .Parse (setting .AppURL )
267
-
268
- insecure := ""
269
- if appURL .Scheme == string (setting .HTTP ) {
270
- insecure = "--insecure "
271
- }
272
- ctx .Header ().Set ("Content-Type" , "text/html" )
273
- ctx .Status (http .StatusOK )
274
- _ , _ = ctx .Write ([]byte (com .Expand (`<!doctype html>
275
- <html>
276
- <head>
277
- <meta name="go-import" content="{GoGetImport} git {CloneLink}">
278
- <meta name="go-source" content="{GoGetImport} _ {GoDocDirectory} {GoDocFile}">
279
- </head>
280
- <body>
281
- go get {Insecure}{GoGetImport}
282
- </body>
283
- </html>
284
- ` , map [string ]string {
285
- "GoGetImport" : context .ComposeGoGetImport (ownerName , trimmedRepoName ),
286
- "CloneLink" : models .ComposeHTTPSCloneURL (ownerName , repoName ),
287
- "GoDocDirectory" : prefix + "{/dir}" ,
288
- "GoDocFile" : prefix + "{/dir}/{file}#L{line}" ,
289
- "Insecure" : insecure ,
290
- })))
291
- }
292
-
293
230
// RegisterRoutes register routes
294
231
func RegisterRoutes (m * web.Route ) {
295
232
reqSignIn := context .Toggle (& context.ToggleOptions {SignInRequired : true })
@@ -1091,7 +1028,7 @@ func RegisterRoutes(m *web.Route) {
1091
1028
m .Group ("/{username}" , func () {
1092
1029
m .Group ("/{reponame}" , func () {
1093
1030
m .Get ("" , repo .SetEditorconfigIfExists , repo .Home )
1094
- }, goGet , ignSignIn , context .RepoAssignment , context .RepoRef (), context .UnitTypes ())
1031
+ }, ignSignIn , context .RepoAssignment , context .RepoRef (), context .UnitTypes ())
1095
1032
1096
1033
m .Group ("/{reponame}" , func () {
1097
1034
m .Group ("/info/lfs" , func () {
0 commit comments