@@ -10,6 +10,7 @@ import (
10
10
"html/template"
11
11
"io"
12
12
"net/http"
13
+ "path"
13
14
"strings"
14
15
"time"
15
16
@@ -18,6 +19,7 @@ import (
18
19
"code.gitea.io/gitea/modules/base"
19
20
"code.gitea.io/gitea/modules/log"
20
21
"code.gitea.io/gitea/modules/setting"
22
+ "github.com/Unknwon/com"
21
23
"github.com/go-macaron/cache"
22
24
"github.com/go-macaron/csrf"
23
25
"github.com/go-macaron/i18n"
@@ -33,6 +35,7 @@ type Context struct {
33
35
Flash * session.Flash
34
36
Session session.Store
35
37
38
+ Link string // current request URL
36
39
User * models.User
37
40
IsSigned bool
38
41
IsBasicAuth bool
@@ -154,15 +157,50 @@ func Contexter() macaron.Handler {
154
157
csrf : x ,
155
158
Flash : f ,
156
159
Session : sess ,
160
+ Link : setting .AppSubURL + strings .TrimSuffix (c .Req .URL .Path , "/" ),
157
161
Repo : & Repository {
158
162
PullRequest : & PullRequest {},
159
163
},
160
164
Org : & Organization {},
161
165
}
162
- // Compute current URL for real-time change language.
163
- ctx .Data ["Link" ] = setting .AppSubURL + strings .TrimSuffix (ctx .Req .URL .Path , "/" )
164
-
166
+ c .Data ["Link" ] = ctx .Link
165
167
ctx .Data ["PageStartTime" ] = time .Now ()
168
+ // Quick responses appropriate go-get meta with status 200
169
+ // regardless of if user have access to the repository,
170
+ // or the repository does not exist at all.
171
+ // This is particular a workaround for "go get" command which does not respect
172
+ // .netrc file.
173
+ if ctx .Query ("go-get" ) == "1" {
174
+ ownerName := c .Params (":username" )
175
+ repoName := c .Params (":reponame" )
176
+ branchName := "master"
177
+
178
+ owner , err := models .GetUserByName (ownerName )
179
+ if err == nil {
180
+ repo , err := models .GetRepositoryByName (owner .ID , repoName )
181
+ if err == nil && len (repo .DefaultBranch ) > 0 {
182
+ branchName = repo .DefaultBranch
183
+ }
184
+ }
185
+ prefix := setting .AppURL + path .Join (ownerName , repoName , "src" , branchName )
186
+ c .PlainText (http .StatusOK , []byte (com .Expand (`
187
+ <html>
188
+ <head>
189
+ <meta name="go-import" content="{GoGetImport} git {CloneLink}">
190
+ <meta name="go-source" content="{GoGetImport} _ {GoDocDirectory} {GoDocFile}">
191
+ </head>
192
+ <body>
193
+ go get {GoGetImport}
194
+ </body>
195
+ </html>
196
+ ` , map [string ]string {
197
+ "GoGetImport" : path .Join (setting .Domain , setting .AppSubURL , ctx .Link ),
198
+ "CloneLink" : models .ComposeHTTPSCloneURL (ownerName , repoName ),
199
+ "GoDocDirectory" : prefix + "{/dir}" ,
200
+ "GoDocFile" : prefix + "{/dir}/{file}#L{line}" ,
201
+ })))
202
+ return
203
+ }
166
204
167
205
// Get user from session if logged in.
168
206
ctx .User , ctx .IsBasicAuth = auth .SignedInUser (ctx .Context , ctx .Session )
0 commit comments