ServeGoGet does quick responses for appropriate go-get meta with status OK regardless of whether the user has access to the repository, or the repository does exist at all. This is particular a workaround for "go get" command which does not respect .netrc file.
()
| 18 | // does exist at all. This is particular a workaround for "go get" command which |
| 19 | // does not respect .netrc file. |
| 20 | func ServeGoGet() macaron.Handler { |
| 21 | return func(c *macaron.Context) { |
| 22 | if c.Query("go-get") != "1" { |
| 23 | return |
| 24 | } |
| 25 | |
| 26 | ownerName := c.Params(":username") |
| 27 | repoName := c.Params(":reponame") |
| 28 | branchName := "master" |
| 29 | |
| 30 | owner, err := database.Handle.Users().GetByUsername(c.Req.Context(), ownerName) |
| 31 | if err == nil { |
| 32 | repo, err := database.Handle.Repositories().GetByName(c.Req.Context(), owner.ID, repoName) |
| 33 | if err == nil && repo.DefaultBranch != "" { |
| 34 | branchName = repo.DefaultBranch |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | prefix := conf.Server.ExternalURL + path.Join(ownerName, repoName, "src", branchName) |
| 39 | insecureFlag := "" |
| 40 | if !strings.HasPrefix(conf.Server.ExternalURL, "https://") { |
| 41 | insecureFlag = "--insecure " |
| 42 | } |
| 43 | c.PlainText(http.StatusOK, []byte(com.Expand(`<!doctype html> |
| 44 | <html> |
| 45 | <head> |
| 46 | <meta name="go-import" content="{GoGetImport} git {CloneLink}"> |
| 47 | <meta name="go-source" content="{GoGetImport} _ {GoDocDirectory} {GoDocFile}"> |
| 48 | </head> |
| 49 | <body> |
| 50 | go get {InsecureFlag}{GoGetImport} |
| 51 | </body> |
| 52 | </html> |
| 53 | `, |
| 54 | map[string]string{ |
| 55 | "GoGetImport": path.Join(conf.Server.URL.Host, conf.Server.Subpath, ownerName, repoName), |
| 56 | "CloneLink": repoutil.HTTPSCloneURL(ownerName, repoName), |
| 57 | "GoDocDirectory": prefix + "{/dir}", |
| 58 | "GoDocFile": prefix + "{/dir}/{file}#L{line}", |
| 59 | "InsecureFlag": insecureFlag, |
| 60 | }, |
| 61 | ))) |
| 62 | } |
| 63 | } |
no test coverage detected