gddo-server: update PkgGoDevURL logic

The logic for PkgGoDevURL is updated:

- The ?tab=doc query param is removed
- The ?tab=packages query param is removed
- Requests for the godoc.org badge SVG are teed to the pkg.go.dev badge SVG
- Requests to godoc.org/C are explicitly teed to pkg.go.dev/C

Change-Id: If5bd6259a88e921b8175e993ea574ea47947e1ca
Reviewed-on: https://go-review.googlesource.com/c/gddo/+/274859
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Trust: Julie Qiu <julie@golang.org>
diff --git a/gddo-server/pkgsite.go b/gddo-server/pkgsite.go
index be1d3b8..b14e320 100644
--- a/gddo-server/pkgsite.go
+++ b/gddo-server/pkgsite.go
@@ -178,9 +178,10 @@
 	switch godocURL.Path {
 	case "/-/go":
 		u.Path = "/std"
-		q.Add("tab", "packages")
 	case "/-/about":
 		u.Path = "/about"
+	case "/C":
+		u.Path = "/C"
 	case "/":
 		if qparam := godocURL.Query().Get("q"); qparam != "" {
 			u.Path = "/search"
@@ -193,13 +194,18 @@
 		q.Set("q", "golang.org/x")
 	default:
 		{
+			_, isSVG := godocURL.Query()["status.svg"]
+			_, isPNG := godocURL.Query()["status.png"]
+			if isSVG || isPNG {
+				u.Path = "/badge" + godocURL.Path
+				break
+			}
+
 			u.Path = godocURL.Path
 			if _, ok := godocURL.Query()["imports"]; ok {
 				q.Set("tab", "imports")
 			} else if _, ok := godocURL.Query()["importers"]; ok {
 				q.Set("tab", "importedby")
-			} else {
-				q.Set("tab", "doc")
 			}
 		}
 	}
diff --git a/gddo-server/pkgsite_test.go b/gddo-server/pkgsite_test.go
index a4593ee..8515db6 100644
--- a/gddo-server/pkgsite_test.go
+++ b/gddo-server/pkgsite_test.go
@@ -30,7 +30,7 @@
 		{
 			name:                "test pkggodev-redirect param is on",
 			url:                 "http://godoc.org/net/http?redirect=on",
-			wantLocationHeader:  "https://pkg.go.dev/net/http?tab=doc&utm_source=godoc",
+			wantLocationHeader:  "https://pkg.go.dev/net/http?utm_source=godoc",
 			wantSetCookieHeader: "pkggodev-redirect=on; Path=/",
 			wantStatusCode:      http.StatusFound,
 		},
@@ -60,7 +60,7 @@
 			name:                "pkggodev-redirect enabled cookie should redirect",
 			url:                 "http://godoc.org/net/http",
 			cookie:              &http.Cookie{Name: "pkggodev-redirect", Value: "on"},
-			wantLocationHeader:  "https://pkg.go.dev/net/http?tab=doc&utm_source=godoc",
+			wantLocationHeader:  "https://pkg.go.dev/net/http?utm_source=godoc",
 			wantSetCookieHeader: "",
 			wantStatusCode:      http.StatusFound,
 		},
@@ -99,29 +99,37 @@
 	}
 }
 
-func TestGodoc(t *testing.T) {
+func TestPkgGoDevURL(t *testing.T) {
 	testCases := []struct {
 		from, to string
 	}{
 		{
+			from: "https://godoc.org",
+			to:   "https://pkg.go.dev?utm_source=godoc",
+		},
+		{
 			from: "https://godoc.org/-/about",
 			to:   "https://pkg.go.dev/about?utm_source=godoc",
 		},
 		{
 			from: "https://godoc.org/-/go",
-			to:   "https://pkg.go.dev/std?tab=packages&utm_source=godoc",
+			to:   "https://pkg.go.dev/std?utm_source=godoc",
 		},
 		{
 			from: "https://godoc.org/-/subrepo",
 			to:   "https://pkg.go.dev/search?q=golang.org%2Fx&utm_source=godoc",
 		},
 		{
+			from: "https://godoc.org/C",
+			to:   "https://pkg.go.dev/C?utm_source=godoc",
+		},
+		{
 			from: "https://godoc.org/?q=foo",
 			to:   "https://pkg.go.dev/search?q=foo&utm_source=godoc",
 		},
 		{
 			from: "https://godoc.org/cloud.google.com/go/storage",
-			to:   "https://pkg.go.dev/cloud.google.com/go/storage?tab=doc&utm_source=godoc",
+			to:   "https://pkg.go.dev/cloud.google.com/go/storage?utm_source=godoc",
 		},
 		{
 			from: "https://godoc.org/cloud.google.com/go/storage?imports",
@@ -132,6 +140,14 @@
 			to:   "https://pkg.go.dev/cloud.google.com/go/storage?tab=importedby&utm_source=godoc",
 		},
 		{
+			from: "https://godoc.org/cloud.google.com/go/storage?status.svg",
+			to:   "https://pkg.go.dev/badge/cloud.google.com/go/storage?utm_source=godoc",
+		},
+		{
+			from: "https://godoc.org/cloud.google.com/go/storage?status.png",
+			to:   "https://pkg.go.dev/badge/cloud.google.com/go/storage?utm_source=godoc",
+		},
+		{
 			from: "https://godoc.org/golang.org/x/vgo/vendor/cmd/go/internal/modfile",
 			to:   "https://pkg.go.dev/?utm_source=godoc",
 		},