OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package main | 5 package main |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "flag" | 9 "flag" |
10 "fmt" | 10 "fmt" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 fsMap.Init(*path) | 101 fsMap.Init(*path) |
102 fileServer = http.FileServer(*goroot, "") | 102 fileServer = http.FileServer(*goroot, "") |
103 cmdHandler = httpHandler{"/cmd/", pathutil.Join(*goroot, "src/cmd"), fal
se} | 103 cmdHandler = httpHandler{"/cmd/", pathutil.Join(*goroot, "src/cmd"), fal
se} |
104 pkgHandler = httpHandler{"/pkg/", pathutil.Join(*goroot, "src/pkg"), tru
e} | 104 pkgHandler = httpHandler{"/pkg/", pathutil.Join(*goroot, "src/pkg"), tru
e} |
105 } | 105 } |
106 | 106 |
107 | 107 |
108 func registerPublicHandlers(mux *http.ServeMux) { | 108 func registerPublicHandlers(mux *http.ServeMux) { |
109 mux.Handle(cmdHandler.pattern, &cmdHandler) | 109 mux.Handle(cmdHandler.pattern, &cmdHandler) |
110 mux.Handle(pkgHandler.pattern, &pkgHandler) | 110 mux.Handle(pkgHandler.pattern, &pkgHandler) |
111 » mux.Handle("/search", http.HandlerFunc(search)) | 111 » mux.HandleFunc("/doc/codewalk/", codewalk) |
112 » mux.Handle("/", http.HandlerFunc(serveFile)) | 112 » mux.HandleFunc("/search", search) |
| 113 » mux.HandleFunc("/", serveFile) |
113 } | 114 } |
114 | 115 |
115 | 116 |
116 // ---------------------------------------------------------------------------- | 117 // ---------------------------------------------------------------------------- |
117 // Predicates and small utility functions | 118 // Predicates and small utility functions |
118 | 119 |
119 func isGoFile(f *os.FileInfo) bool { | 120 func isGoFile(f *os.FileInfo) bool { |
120 return f.IsRegular() && | 121 return f.IsRegular() && |
121 !strings.HasPrefix(f.Name, ".") && // ignore .files | 122 !strings.HasPrefix(f.Name, ".") && // ignore .files |
122 pathutil.Ext(f.Name) == ".go" | 123 pathutil.Ext(f.Name) == ".go" |
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 } | 843 } |
843 t, err := template.Parse(string(data), fmap) | 844 t, err := template.Parse(string(data), fmap) |
844 if err != nil { | 845 if err != nil { |
845 log.Exitf("%s: %v", name, err) | 846 log.Exitf("%s: %v", name, err) |
846 } | 847 } |
847 return t | 848 return t |
848 } | 849 } |
849 | 850 |
850 | 851 |
851 var ( | 852 var ( |
| 853 codewalkHTML, |
| 854 codewalkdirHTML, |
852 dirlistHTML, | 855 dirlistHTML, |
853 errorHTML, | 856 errorHTML, |
854 godocHTML, | 857 godocHTML, |
855 packageHTML, | 858 packageHTML, |
856 packageText, | 859 packageText, |
857 searchHTML, | 860 searchHTML, |
858 searchText, | 861 searchText, |
859 sourceHTML *template.Template | 862 sourceHTML *template.Template |
860 ) | 863 ) |
861 | 864 |
862 func readTemplates() { | 865 func readTemplates() { |
863 // have to delay until after flags processing since paths depend on goro
ot | 866 // have to delay until after flags processing since paths depend on goro
ot |
| 867 codewalkHTML = readTemplate("codewalk.html") |
| 868 codewalkdirHTML = readTemplate("codewalkdir.html") |
864 dirlistHTML = readTemplate("dirlist.html") | 869 dirlistHTML = readTemplate("dirlist.html") |
865 errorHTML = readTemplate("error.html") | 870 errorHTML = readTemplate("error.html") |
866 godocHTML = readTemplate("godoc.html") | 871 godocHTML = readTemplate("godoc.html") |
867 packageHTML = readTemplate("package.html") | 872 packageHTML = readTemplate("package.html") |
868 packageText = readTemplate("package.txt") | 873 packageText = readTemplate("package.txt") |
869 searchHTML = readTemplate("search.html") | 874 searchHTML = readTemplate("search.html") |
870 searchText = readTemplate("search.txt") | 875 searchText = readTemplate("search.txt") |
871 sourceHTML = readTemplate("source.html") | 876 sourceHTML = readTemplate("source.html") |
872 } | 877 } |
873 | 878 |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1407 nwords, nspots := index.Size() | 1412 nwords, nspots := index.Size() |
1408 log.Stderrf("index updated (%gs, %d unique words
, %d spots)", secs, nwords, nspots) | 1413 log.Stderrf("index updated (%gs, %d unique words
, %d spots)", secs, nwords, nspots) |
1409 } | 1414 } |
1410 log.Stderrf("bytes=%d footprint=%d\n", runtime.MemStats.
HeapAlloc, runtime.MemStats.Sys) | 1415 log.Stderrf("bytes=%d footprint=%d\n", runtime.MemStats.
HeapAlloc, runtime.MemStats.Sys) |
1411 runtime.GC() | 1416 runtime.GC() |
1412 log.Stderrf("bytes=%d footprint=%d\n", runtime.MemStats.
HeapAlloc, runtime.MemStats.Sys) | 1417 log.Stderrf("bytes=%d footprint=%d\n", runtime.MemStats.
HeapAlloc, runtime.MemStats.Sys) |
1413 } | 1418 } |
1414 time.Sleep(1 * 60e9) // try once a minute | 1419 time.Sleep(1 * 60e9) // try once a minute |
1415 } | 1420 } |
1416 } | 1421 } |
OLD | NEW |