Skip to content

Commit 5b36379

Browse files
authored
Fix go get response if only app URL is custom in configuration (#2634) (#2640)
* Fix go get response if only app URL is custom in configuration * Rewrite to update Domain setting to match AppURL
1 parent e38e502 commit 5b36379

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

modules/context/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func Contexter() macaron.Handler {
194194
</body>
195195
</html>
196196
`, map[string]string{
197-
"GoGetImport": path.Join(setting.Domain, setting.AppSubURL, ctx.Link),
197+
"GoGetImport": ComposeGoGetImport(ownerName, strings.TrimSuffix(repoName, ".git")),
198198
"CloneLink": models.ComposeHTTPSCloneURL(ownerName, repoName),
199199
"GoDocDirectory": prefix + "{/dir}",
200200
"GoDocFile": prefix + "{/dir}/{file}#L{line}",

modules/setting/setting.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"encoding/base64"
1111
"fmt"
1212
"io"
13+
"net"
1314
"net/mail"
1415
"net/url"
1516
"os"
@@ -657,6 +658,12 @@ func NewContext() {
657658
// This value is empty if site does not have sub-url.
658659
AppSubURL = strings.TrimSuffix(url.Path, "/")
659660
AppSubURLDepth = strings.Count(AppSubURL, "/")
661+
// Check if Domain differs from AppURL domain than update it to AppURL's domain
662+
// TODO: Can be replaced with url.Hostname() when minimal GoLang version is 1.8
663+
urlHostname := strings.SplitN(url.Host, ":", 2)[0]
664+
if urlHostname != Domain && net.ParseIP(urlHostname) == nil {
665+
Domain = urlHostname
666+
}
660667

661668
var defaultLocalURL string
662669
switch Protocol {

0 commit comments

Comments
 (0)