Skip to content

Commit 46cc45f

Browse files
lafrikslunny
authored andcommitted
Fix go get response if only app URL is custom in configuration (#2634)
* Fix go get response if only app URL is custom in configuration * Rewrite to update Domain setting to match AppURL
1 parent a8717e5 commit 46cc45f

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"
@@ -664,6 +665,12 @@ func NewContext() {
664665
// This value is empty if site does not have sub-url.
665666
AppSubURL = strings.TrimSuffix(url.Path, "/")
666667
AppSubURLDepth = strings.Count(AppSubURL, "/")
668+
// Check if Domain differs from AppURL domain than update it to AppURL's domain
669+
// TODO: Can be replaced with url.Hostname() when minimal GoLang version is 1.8
670+
urlHostname := strings.SplitN(url.Host, ":", 2)[0]
671+
if urlHostname != Domain && net.ParseIP(urlHostname) == nil {
672+
Domain = urlHostname
673+
}
667674

668675
var defaultLocalURL string
669676
switch Protocol {

0 commit comments

Comments
 (0)