// 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"}, "benchmarks": {"https://go.googlesource.com/benchmarks", "git"}, "blog": {"https://go.googlesource.com/blog", "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"}, "mobile": {"https://go.googlesource.com/mobile", "git"}, "net": {"https://go.googlesource.com/net", "git"}, "oauth2": {"https://go.googlesource.com/oauth2", "git"}, "review": {"https://go.googlesource.com/review", "git"}, "sys": {"https://go.googlesource.com/sys", "git"}, "talks": {"https://go.googlesource.com/talks", "git"}, "text": {"https://go.googlesource.com/text", "git"}, "tools": {"https://go.googlesource.com/tools", "git"}, } 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 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(` Nothing to see here; move along. `))