Skip to content
Permalink
Browse files

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>
  • 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 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 (
@@ -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...)
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

0 comments on commit ee56168

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