]> source.dussan.org Git - gitea.git/commitdiff
Fix go get response if only app URL is custom in configuration (#2634)
authorLauris BH <lauris@nix.lv>
Mon, 2 Oct 2017 13:55:09 +0000 (16:55 +0300)
committerLunny Xiao <xiaolunwen@gmail.com>
Mon, 2 Oct 2017 13:55:09 +0000 (21:55 +0800)
* Fix go get response if only app URL is custom in configuration

* Rewrite to update Domain setting to match AppURL

modules/context/context.go
modules/setting/setting.go

index 7137a16723031290590b903bac4dad7b89828d0f..9f5d934e4d629a12d692cf0a6a016c6f935f56e4 100644 (file)
@@ -194,7 +194,7 @@ func Contexter() macaron.Handler {
        </body>
 </html>
 `, 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}",
index f5941255030d2b45d6abd3b4bae5179fcc503d80..6b1b269b73481c81e32cff458aad31f20ab83519 100644 (file)
@@ -10,6 +10,7 @@ import (
        "encoding/base64"
        "fmt"
        "io"
+       "net"
        "net/mail"
        "net/url"
        "os"
@@ -664,6 +665,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 {