2014-10-30 16:01:52 -06:00
|
|
|
// 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/"
|
|
|
|
|
2014-11-18 20:03:19 -07:00
|
|
|
type xRepo struct {
|
|
|
|
URL, VCS string
|
|
|
|
}
|
|
|
|
|
|
|
|
var xMap = map[string]xRepo{
|
2018-03-28 10:45:32 -06:00
|
|
|
"codereview": {"https://code.google.com/p/go.codereview", "hg"}, // Not included at https://golang.org/pkg/#subrepo.
|
2014-11-18 20:03:19 -07:00
|
|
|
|
2018-03-28 10:45:32 -06:00
|
|
|
"arch": {"https://go.googlesource.com/arch", "git"}, // Not included at https://golang.org/pkg/#subrepo.
|
2014-12-07 16:30:52 -07:00
|
|
|
"benchmarks": {"https://go.googlesource.com/benchmarks", "git"},
|
|
|
|
"blog": {"https://go.googlesource.com/blog", "git"},
|
2015-01-20 23:58:44 -07:00
|
|
|
"build": {"https://go.googlesource.com/build", "git"},
|
2014-12-07 16:30:52 -07:00
|
|
|
"crypto": {"https://go.googlesource.com/crypto", "git"},
|
2014-12-14 21:37:18 -07:00
|
|
|
"debug": {"https://go.googlesource.com/debug", "git"},
|
2014-12-07 16:30:52 -07:00
|
|
|
"exp": {"https://go.googlesource.com/exp", "git"},
|
|
|
|
"image": {"https://go.googlesource.com/image", "git"},
|
2018-03-28 10:45:32 -06:00
|
|
|
"lint": {"https://go.googlesource.com/lint", "git"}, // Not included at https://golang.org/pkg/#subrepo.
|
2014-12-07 16:30:52 -07:00
|
|
|
"mobile": {"https://go.googlesource.com/mobile", "git"},
|
|
|
|
"net": {"https://go.googlesource.com/net", "git"},
|
2018-03-28 10:45:32 -06:00
|
|
|
"oauth2": {"https://go.googlesource.com/oauth2", "git"}, // Not included at https://golang.org/pkg/#subrepo.
|
2016-12-20 13:06:13 -07:00
|
|
|
"perf": {"https://go.googlesource.com/perf", "git"},
|
2018-03-28 10:45:32 -06:00
|
|
|
"playground": {"https://go.googlesource.com/playground", "git"}, // Not included at https://golang.org/pkg/#subrepo.
|
2014-12-07 16:30:52 -07:00
|
|
|
"review": {"https://go.googlesource.com/review", "git"},
|
2015-11-03 19:23:52 -07:00
|
|
|
"sync": {"https://go.googlesource.com/sync", "git"},
|
2014-12-07 16:30:52 -07:00
|
|
|
"sys": {"https://go.googlesource.com/sys", "git"},
|
2018-03-28 10:45:32 -06:00
|
|
|
"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.
|
2014-12-07 16:30:52 -07:00
|
|
|
"text": {"https://go.googlesource.com/text", "git"},
|
2015-11-03 19:23:52 -07:00
|
|
|
"time": {"https://go.googlesource.com/time", "git"},
|
2014-12-07 16:30:52 -07:00
|
|
|
"tools": {"https://go.googlesource.com/tools", "git"},
|
2015-02-09 22:33:58 -07:00
|
|
|
"tour": {"https://go.googlesource.com/tour", "git"},
|
2019-01-04 09:54:00 -07:00
|
|
|
"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.
|
2019-01-25 16:07:50 -07:00
|
|
|
"xerrors": {"https://go.googlesource.com/xerrors", "git"}, // Not included at https://golang.org/pkg/#subrepo.
|
2014-10-30 16:01:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
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:]
|
|
|
|
}
|
2015-07-12 07:49:48 -06:00
|
|
|
if head == "" {
|
|
|
|
http.Redirect(w, r, "https://godoc.org/-/subrepo", http.StatusTemporaryRedirect)
|
|
|
|
return
|
|
|
|
}
|
2014-10-30 16:01:52 -06:00
|
|
|
repo, ok := xMap[head]
|
|
|
|
if !ok {
|
|
|
|
http.NotFound(w, r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
data := struct {
|
2014-11-18 20:03:19 -07:00
|
|
|
Prefix, Head, Tail string
|
|
|
|
Repo xRepo
|
2014-10-30 16:01:52 -06:00
|
|
|
}{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"/>
|
2014-11-18 20:03:19 -07:00
|
|
|
<meta name="go-import" content="golang.org{{.Prefix}}{{.Head}} {{.Repo.VCS}} {{.Repo.URL}}">
|
2015-01-13 17:45:42 -07:00
|
|
|
<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}">
|
2014-10-30 16:01:52 -06:00
|
|
|
<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>
|
|
|
|
`))
|