@@ -124,21 +124,23 @@ func RetrieveBaseRepo(ctx *Context, repo *models.Repository) {
124124}
125125}
126126
127- // composeGoGetImport returns go-get-import meta content.
128- func composeGoGetImport (owner , repo string ) string {
127+ // ComposeGoGetImport returns go-get-import meta content.
128+ func ComposeGoGetImport (owner , repo string ) string {
129129return path .Join (setting .Domain , setting .AppSubURL , owner , repo )
130130}
131131
132- // earlyResponseForGoGetMeta responses appropriate go-get meta with status 200
132+ // EarlyResponseForGoGetMeta responses appropriate go-get meta with status 200
133133// if user does not have actual access to the requested repository,
134134// or the owner or repository does not exist at all.
135135// This is particular a workaround for "go get" command which does not respect
136136// .netrc file.
137- func earlyResponseForGoGetMeta (ctx * Context ) {
137+ func EarlyResponseForGoGetMeta (ctx * Context ) {
138+ username := ctx .Params (":username" )
139+ reponame := ctx .Params (":reponame" )
138140ctx .PlainText (200 , []byte (com .Expand (`<meta name="go-import" content="{GoGetImport} git {CloneLink}">` ,
139141map [string ]string {
140- "GoGetImport" : composeGoGetImport ( ctx . Params ( ": username" ) , strings .TrimSuffix (ctx . Params ( ": reponame" ) , ".git" )),
141- "CloneLink" : models .ComposeHTTPSCloneURL (ctx . Params ( ": username" ), ctx . Params ( ": reponame" ) ),
142+ "GoGetImport" : ComposeGoGetImport ( username , strings .TrimSuffix (reponame , ".git" )),
143+ "CloneLink" : models .ComposeHTTPSCloneURL (username , reponame ),
142144})))
143145}
144146
@@ -206,7 +208,7 @@ func RepoIDAssignment() macaron.Handler {
206208// Check access.
207209if ctx .Repo .AccessMode == models .AccessModeNone {
208210if ctx .Query ("go-get" ) == "1" {
209- earlyResponseForGoGetMeta (ctx )
211+ EarlyResponseForGoGetMeta (ctx )
210212return
211213}
212214ctx .Handle (404 , "no access right" , err )
@@ -250,7 +252,7 @@ func RepoAssignment() macaron.Handler {
250252if err != nil {
251253if models .IsErrUserNotExist (err ) {
252254if ctx .Query ("go-get" ) == "1" {
253- earlyResponseForGoGetMeta (ctx )
255+ EarlyResponseForGoGetMeta (ctx )
254256return
255257}
256258ctx .Handle (404 , "GetUserByName" , nil )
@@ -272,7 +274,7 @@ func RepoAssignment() macaron.Handler {
272274RedirectToRepo (ctx , redirectRepoID )
273275} else if models .IsErrRepoRedirectNotExist (err ) {
274276if ctx .Query ("go-get" ) == "1" {
275- earlyResponseForGoGetMeta (ctx )
277+ EarlyResponseForGoGetMeta (ctx )
276278return
277279}
278280ctx .Handle (404 , "GetRepositoryByName" , nil )
@@ -305,7 +307,7 @@ func RepoAssignment() macaron.Handler {
305307// Check access.
306308if ctx .Repo .AccessMode == models .AccessModeNone {
307309if ctx .Query ("go-get" ) == "1" {
308- earlyResponseForGoGetMeta (ctx )
310+ EarlyResponseForGoGetMeta (ctx )
309311return
310312}
311313ctx .Handle (404 , "no access right" , err )
@@ -433,7 +435,7 @@ func RepoAssignment() macaron.Handler {
433435ctx .Data ["PullRequestCtx" ] = ctx .Repo .PullRequest
434436
435437if ctx .Query ("go-get" ) == "1" {
436- ctx .Data ["GoGetImport" ] = composeGoGetImport (owner .Name , repo .Name )
438+ ctx .Data ["GoGetImport" ] = ComposeGoGetImport (owner .Name , repo .Name )
437439prefix := setting .AppURL + path .Join (owner .Name , repo .Name , "src" , ctx .Repo .BranchName )
438440ctx .Data ["GoDocDirectory" ] = prefix + "{/dir}"
439441ctx .Data ["GoDocFile" ] = prefix + "{/dir}/{file}#L{line}"
0 commit comments