Skip to content
Browse files

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

This change adds an optional query parameter, include=all, to the 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-by: Brad Fitzpatrick <>
Run-TryBot: Brad Fitzpatrick <>
TryBot-Result: Gobot Gobot <>
  • Loading branch information...
johnweldon authored and agnivade committed Feb 26, 2019
1 parent c7db086 commit ee561689b91f03b9d60196ef5afe5b16645f48d0
Showing with 20 additions and 1 deletion.
  1. +12 −0 internal/dl/dl.go
  2. +8 −1 internal/dl/server.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
// The package also serves the list of downloads at:
// An optional query param, mode=json, serves the list of stable release
// downloads in JSON format:
// 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:
package dl

import (
@@ -78,10 +78,17 @@ func (h server) listHandler(w http.ResponseWriter, r *http.Request) {

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...)
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)

0 comments on commit ee56168

Please sign in to comment.
You can’t perform that action at this time.