internal/dl: enhance JSON download with include=all option

This change adds an optional query parameter, include=all, to the
https://godoc.org/dl/?mode=json endpoint. When this parameter is set
the returned JSON will include metadata for Stable, Archive, and
Unstable downloads, rather than the default which only lists Stable.

Fixes golang/go#29380

Change-Id: Id51e839919df9dd967d2f11ba0658f51f61b6d1b
Reviewed-on: https://go-review.googlesource.com/c/website/+/163741
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/internal/dl/dl.go b/internal/dl/dl.go
index aaa7af4..1c8abe2 100644
--- a/internal/dl/dl.go
+++ b/internal/dl/dl.go
@@ -7,6 +7,18 @@
 // It accepts HTTP POST requests to create a new download metadata entity, and
 // lists entities with sorting and filtering.
 // It is designed to run only on the instance of godoc that serves golang.org.
+//
+// The package also serves the list of downloads at:
+//     https://golang.org/dl/
+//
+// An optional query param, mode=json, serves the list of stable release
+// downloads in JSON format:
+//     https://golang.org/dl/?mode=json
+//
+// An additional query param, include=all, when used with the mode=json
+// query param, will serve a full list of available downloads, including
+// stable, unstable, and archived releases in JSON format:
+//     https://golang.org/dl/?mode=json&include=all
 package dl
 
 import (
diff --git a/internal/dl/server.go b/internal/dl/server.go
index 342863f..b69b55a 100644
--- a/internal/dl/server.go
+++ b/internal/dl/server.go
@@ -78,10 +78,17 @@
 	}
 
 	if r.URL.Query().Get("mode") == "json" {
+		var releases []Release
+		switch r.URL.Query().Get("include") {
+		case "all":
+			releases = append(append(d.Stable, d.Archive...), d.Unstable...)
+		default:
+			releases = d.Stable
+		}
 		w.Header().Set("Content-Type", "application/json")
 		enc := json.NewEncoder(w)
 		enc.SetIndent("", " ")
-		if err := enc.Encode(d.Stable); err != nil {
+		if err := enc.Encode(releases); err != nil {
 			log.Printf("ERROR rendering JSON for releases: %v", err)
 		}
 		return