mirror of
https://github.com/golang/go
synced 2024-11-18 13:14:47 -07:00
9ea1c200b2
Add a redirect for the recently created x/website subrepository. It's not yet included at https://golang.org/pkg/#subrepo because it's in development. Once development reaches the point that x/website is the canonical location of the golang.org server, we can consider including x/website at https://golang.org/pkg/#subrepo (just like x/blog, x/tour, x/build are already included there). Updates golang/go#29206 Change-Id: I6889c1f5e40f11abca944b217a7354f76c08c8eb Reviewed-on: https://go-review.googlesource.com/c/156337 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
94 lines
3.8 KiB
Go
94 lines
3.8 KiB
Go
// 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/"
|
|
|
|
type xRepo struct {
|
|
URL, VCS string
|
|
}
|
|
|
|
var xMap = map[string]xRepo{
|
|
"codereview": {"https://code.google.com/p/go.codereview", "hg"}, // Not included at https://golang.org/pkg/#subrepo.
|
|
|
|
"arch": {"https://go.googlesource.com/arch", "git"}, // Not included at https://golang.org/pkg/#subrepo.
|
|
"benchmarks": {"https://go.googlesource.com/benchmarks", "git"},
|
|
"blog": {"https://go.googlesource.com/blog", "git"},
|
|
"build": {"https://go.googlesource.com/build", "git"},
|
|
"crypto": {"https://go.googlesource.com/crypto", "git"},
|
|
"debug": {"https://go.googlesource.com/debug", "git"},
|
|
"exp": {"https://go.googlesource.com/exp", "git"},
|
|
"image": {"https://go.googlesource.com/image", "git"},
|
|
"lint": {"https://go.googlesource.com/lint", "git"}, // Not included at https://golang.org/pkg/#subrepo.
|
|
"mobile": {"https://go.googlesource.com/mobile", "git"},
|
|
"net": {"https://go.googlesource.com/net", "git"},
|
|
"oauth2": {"https://go.googlesource.com/oauth2", "git"}, // Not included at https://golang.org/pkg/#subrepo.
|
|
"perf": {"https://go.googlesource.com/perf", "git"},
|
|
"playground": {"https://go.googlesource.com/playground", "git"}, // Not included at https://golang.org/pkg/#subrepo.
|
|
"review": {"https://go.googlesource.com/review", "git"},
|
|
"sync": {"https://go.googlesource.com/sync", "git"},
|
|
"sys": {"https://go.googlesource.com/sys", "git"},
|
|
"talks": {"https://go.googlesource.com/talks", "git"}, // Not included at https://golang.org/pkg/#subrepo.
|
|
"term": {"https://go.googlesource.com/term", "git"}, // Not included at https://golang.org/pkg/#subrepo.
|
|
"text": {"https://go.googlesource.com/text", "git"},
|
|
"time": {"https://go.googlesource.com/time", "git"},
|
|
"tools": {"https://go.googlesource.com/tools", "git"},
|
|
"tour": {"https://go.googlesource.com/tour", "git"},
|
|
"vgo": {"https://go.googlesource.com/vgo", "git"}, // Not included at https://golang.org/pkg/#subrepo.
|
|
"website": {"https://go.googlesource.com/website", "git"}, // Not included at https://golang.org/pkg/#subrepo.
|
|
}
|
|
|
|
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:]
|
|
}
|
|
if head == "" {
|
|
http.Redirect(w, r, "https://godoc.org/-/subrepo", http.StatusTemporaryRedirect)
|
|
return
|
|
}
|
|
repo, ok := xMap[head]
|
|
if !ok {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
data := struct {
|
|
Prefix, Head, Tail string
|
|
Repo xRepo
|
|
}{xPrefix, head, tail, repo}
|
|
if err := xTemplate.Execute(w, data); err != nil {
|
|
log.Println("xHandler:", err)
|
|
}
|
|
}
|
|
|
|
var xTemplate = template.Must(template.New("x").Parse(`<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
|
<meta name="go-import" content="golang.org{{.Prefix}}{{.Head}} {{.Repo.VCS}} {{.Repo.URL}}">
|
|
<meta name="go-source" content="golang.org{{.Prefix}}{{.Head}} https://github.com/golang/{{.Head}}/ https://github.com/golang/{{.Head}}/tree/master{/dir} https://github.com/golang/{{.Head}}/blob/master{/dir}/{file}#L{line}">
|
|
<meta http-equiv="refresh" content="0; url=https://godoc.org/golang.org{{.Prefix}}{{.Head}}{{.Tail}}">
|
|
</head>
|
|
<body>
|
|
Nothing to see here; <a href="https://godoc.org/golang.org{{.Prefix}}{{.Head}}{{.Tail}}">move along</a>.
|
|
</body>
|
|
</html>
|
|
`))
|