github.com/jgarto/itcv@v0.0.0-20180826224514-4eea09c1aa0d/_vendor/src/golang.org/x/tools/cmd/godoc/x.go (about) 1 // Copyright 2013 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // This file contains the handlers that serve go-import redirects for Go 6 // sub-repositories. It specifies the mapping from import paths like 7 // "golang.org/x/tools" to the actual repository locations. 8 9 package main 10 11 import ( 12 "html/template" 13 "log" 14 "net/http" 15 "strings" 16 ) 17 18 const xPrefix = "/x/" 19 20 type xRepo struct { 21 URL, VCS string 22 } 23 24 var xMap = map[string]xRepo{ 25 "codereview": {"https://code.google.com/p/go.codereview", "hg"}, // Not included at https://golang.org/pkg/#subrepo. 26 27 "arch": {"https://go.googlesource.com/arch", "git"}, // Not included at https://golang.org/pkg/#subrepo. 28 "benchmarks": {"https://go.googlesource.com/benchmarks", "git"}, 29 "blog": {"https://go.googlesource.com/blog", "git"}, 30 "build": {"https://go.googlesource.com/build", "git"}, 31 "crypto": {"https://go.googlesource.com/crypto", "git"}, 32 "debug": {"https://go.googlesource.com/debug", "git"}, 33 "exp": {"https://go.googlesource.com/exp", "git"}, 34 "image": {"https://go.googlesource.com/image", "git"}, 35 "lint": {"https://go.googlesource.com/lint", "git"}, // Not included at https://golang.org/pkg/#subrepo. 36 "mobile": {"https://go.googlesource.com/mobile", "git"}, 37 "net": {"https://go.googlesource.com/net", "git"}, 38 "oauth2": {"https://go.googlesource.com/oauth2", "git"}, // Not included at https://golang.org/pkg/#subrepo. 39 "perf": {"https://go.googlesource.com/perf", "git"}, 40 "playground": {"https://go.googlesource.com/playground", "git"}, // Not included at https://golang.org/pkg/#subrepo. 41 "review": {"https://go.googlesource.com/review", "git"}, 42 "sync": {"https://go.googlesource.com/sync", "git"}, 43 "sys": {"https://go.googlesource.com/sys", "git"}, 44 "talks": {"https://go.googlesource.com/talks", "git"}, // Not included at https://golang.org/pkg/#subrepo. 45 "term": {"https://go.googlesource.com/term", "git"}, // Not included at https://golang.org/pkg/#subrepo. 46 "text": {"https://go.googlesource.com/text", "git"}, 47 "time": {"https://go.googlesource.com/time", "git"}, 48 "tools": {"https://go.googlesource.com/tools", "git"}, 49 "tour": {"https://go.googlesource.com/tour", "git"}, 50 "vgo": {"https://go.googlesource.com/vgo", "git"}, // Not included at https://golang.org/pkg/#subrepo. 51 } 52 53 func init() { 54 http.HandleFunc(xPrefix, xHandler) 55 } 56 57 func xHandler(w http.ResponseWriter, r *http.Request) { 58 head, tail := strings.TrimPrefix(r.URL.Path, xPrefix), "" 59 if i := strings.Index(head, "/"); i != -1 { 60 head, tail = head[:i], head[i:] 61 } 62 if head == "" { 63 http.Redirect(w, r, "https://godoc.org/-/subrepo", http.StatusTemporaryRedirect) 64 return 65 } 66 repo, ok := xMap[head] 67 if !ok { 68 http.NotFound(w, r) 69 return 70 } 71 data := struct { 72 Prefix, Head, Tail string 73 Repo xRepo 74 }{xPrefix, head, tail, repo} 75 if err := xTemplate.Execute(w, data); err != nil { 76 log.Println("xHandler:", err) 77 } 78 } 79 80 var xTemplate = template.Must(template.New("x").Parse(`<!DOCTYPE html> 81 <html> 82 <head> 83 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 84 <meta name="go-import" content="golang.org{{.Prefix}}{{.Head}} {{.Repo.VCS}} {{.Repo.URL}}"> 85 <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}"> 86 <meta http-equiv="refresh" content="0; url=https://godoc.org/golang.org{{.Prefix}}{{.Head}}{{.Tail}}"> 87 </head> 88 <body> 89 Nothing to see here; <a href="https://godoc.org/golang.org{{.Prefix}}{{.Head}}{{.Tail}}">move along</a>. 90 </body> 91 </html> 92 `))