diff --git a/modules/context/context.go b/modules/context/context.go index 7137a1672..9f5d934e4 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -194,7 +194,7 @@ func Contexter() macaron.Handler { `, map[string]string{ - "GoGetImport": path.Join(setting.Domain, setting.AppSubURL, ctx.Link), + "GoGetImport": ComposeGoGetImport(ownerName, strings.TrimSuffix(repoName, ".git")), "CloneLink": models.ComposeHTTPSCloneURL(ownerName, repoName), "GoDocDirectory": prefix + "{/dir}", "GoDocFile": prefix + "{/dir}/{file}#L{line}", diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 8cd9fa608..aafe2d1b9 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -10,6 +10,7 @@ import ( "encoding/base64" "fmt" "io" + "net" "net/mail" "net/url" "os" @@ -657,6 +658,12 @@ func NewContext() { // This value is empty if site does not have sub-url. AppSubURL = strings.TrimSuffix(url.Path, "/") AppSubURLDepth = strings.Count(AppSubURL, "/") + // Check if Domain differs from AppURL domain than update it to AppURL's domain + // TODO: Can be replaced with url.Hostname() when minimal GoLang version is 1.8 + urlHostname := strings.SplitN(url.Host, ":", 2)[0] + if urlHostname != Domain && net.ParseIP(urlHostname) == nil { + Domain = urlHostname + } var defaultLocalURL string switch Protocol {