From e3235480e78ee6cfcfe95235f69268bd5821a3df Mon Sep 17 00:00:00 2001 From: Andrew Gerrand Date: Sun, 2 Nov 2014 10:54:05 +1100 Subject: [PATCH] [release-branch.go1.3] go.tools/cmd/godoc: add handlers for new sub-repo paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ««« CL 162470043 / 1e73f4eb4c15 go.tools/cmd/godoc: add handlers for new sub-repo paths Fixes golang/go#9009. LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/162470043 »»» TBR=rsc CC=golang-codereviews https://golang.org/cl/171800043 --- cmd/godoc/x.go | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 cmd/godoc/x.go diff --git a/cmd/godoc/x.go b/cmd/godoc/x.go new file mode 100644 index 00000000..ed7c8d8a --- /dev/null +++ b/cmd/godoc/x.go @@ -0,0 +1,68 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This file contains the handlers that serve go-import redirects for Go +// sub-repositories. It specifies the mapping from import paths like +// "golang.org/x/tools" to the actual repository locations. + +package main + +import ( + "html/template" + "log" + "net/http" + "strings" +) + +const xPrefix = "/x/" + +var xMap = map[string]string{ + "benchmarks": "https://code.google.com/p/go.benchmarks", + "blog": "https://code.google.com/p/go.blog", + "codereview": "https://code.google.com/p/go.codereview", + "crypto": "https://code.google.com/p/go.crypto", + "exp": "https://code.google.com/p/go.exp", + "image": "https://code.google.com/p/go.image", + "mobile": "https://code.google.com/p/go.mobile", + "net": "https://code.google.com/p/go.net", + "sys": "https://code.google.com/p/go.sys", + "talks": "https://code.google.com/p/go.talks", + "text": "https://code.google.com/p/go.text", + "tools": "https://code.google.com/p/go.tools", +} + +func init() { + http.HandleFunc(xPrefix, xHandler) +} + +func xHandler(w http.ResponseWriter, r *http.Request) { + head, tail := strings.TrimPrefix(r.URL.Path, xPrefix), "" + if i := strings.Index(head, "/"); i != -1 { + head, tail = head[:i], head[i:] + } + repo, ok := xMap[head] + if !ok { + http.NotFound(w, r) + return + } + data := struct { + Prefix, Head, Tail, Repo string + }{xPrefix, head, tail, repo} + if err := xTemplate.Execute(w, data); err != nil { + log.Println("xHandler:", err) + } +} + +var xTemplate = template.Must(template.New("x").Parse(` + + + + + + + +Nothing to see here; move along. + + +`))