dmitri.shuralyov.com/website/gido/...

add support for "golang.org/dl/..." issues

The golang.org/dl repo is a special case because it doesn't include
the "x" element like other golang.org/x repos. Handle it specially.

Follows https://dmitri.shuralyov.com/go/prefixtitle/...$commit/500817462677553a6769e268d66193c36b423cd6.
dmitshur committed 2 years ago commit b7141fef43ec3cefbd93cc444ab1f27bdc0a7725
service.go
@@ -419,10 +419,13 @@ func ImportPathToFullPrefix(path string) string {
		// Use all other import paths directly as prefix.
		return path + ": "
	case strings.HasPrefix(path, "golang.org/x/") || path == "golang.org/x":
		// Map "golang.org/x/..." to "x/...".
		return path[len("golang.org/"):] + ": "
	case strings.HasPrefix(path, "golang.org/dl/") || path == "golang.org/dl":
		// Map "golang.org/dl/..." to "dl/...".
		return path[len("golang.org/"):] + ": "
	case path == otherPackages:
		// Empty prefix for otherPackages.
		return ""
	}
}
@@ -436,13 +439,17 @@ func ImportPathsToFullPrefix(paths []string) string {
	var b strings.Builder
	for i, p := range paths {
		if i != 0 {
			b.WriteString(", ")
		}
		if strings.HasPrefix(p, "golang.org/x/") || p == "golang.org/x" {
		switch {
		case strings.HasPrefix(p, "golang.org/x/") || p == "golang.org/x":
			// Map "golang.org/x/..." to "x/...".
			p = p[len("golang.org/"):]
		case strings.HasPrefix(p, "golang.org/dl/") || p == "golang.org/dl":
			// Map "golang.org/dl/..." to "dl/...".
			p = p[len("golang.org/"):]
		}
		b.WriteString(p)
	}
	b.WriteString(": ")
	return b.String()
service_test.go
@@ -21,10 +21,18 @@ func TestImportPathToFullPrefix(t *testing.T) {
		},
		{
			in:   "golang.org/x",
			want: "x: ",
		},
		{
			in:   "golang.org/dl/go1.2.3",
			want: "dl/go1.2.3: ",
		},
		{
			in:   "golang.org/dl",
			want: "dl: ",
		},
		{
			in:   "other",
			want: "",
		},
	}