LEFT | RIGHT |
(no file at all) | |
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 // godoc: Go Documentation Server | 5 // godoc: Go Documentation Server |
6 | 6 |
7 // Web server tree: | 7 // Web server tree: |
8 // | 8 // |
9 // http://godoc/ main landing page | 9 // http://godoc/ main landing page |
10 // http://godoc/doc/ serve from $GOROOT/doc - spec, mem, etc. | 10 // http://godoc/doc/ serve from $GOROOT/doc - spec, mem, etc. |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 log.Printf("full text index enabled (maxresults
= %d)", *maxResults) | 276 log.Printf("full text index enabled (maxresults
= %d)", *maxResults) |
277 default: | 277 default: |
278 log.Print("identifier search index enabled") | 278 log.Print("identifier search index enabled") |
279 } | 279 } |
280 fs.Fprint(os.Stderr) | 280 fs.Fprint(os.Stderr) |
281 handler = loggingHandler(handler) | 281 handler = loggingHandler(handler) |
282 } | 282 } |
283 | 283 |
284 registerPublicHandlers(http.DefaultServeMux) | 284 registerPublicHandlers(http.DefaultServeMux) |
285 | 285 |
286 » » // Playground handlers are not available in local godoc. | 286 » » playHandler := disabledHandler |
287 » » http.HandleFunc("/compile", disabledHandler) | 287 » » if *showPlayground { |
288 » » http.HandleFunc("/share", disabledHandler) | 288 » » » playHandler = bounceToPlayground |
| 289 » » } |
| 290 » » http.HandleFunc("/compile", playHandler) |
| 291 » » http.HandleFunc("/share", playHandler) |
| 292 » » http.HandleFunc("/fmt", playHandler) |
289 | 293 |
290 // Initialize default directory tree with corresponding timestam
p. | 294 // Initialize default directory tree with corresponding timestam
p. |
291 // (Do it in a goroutine so that launch is quick.) | 295 // (Do it in a goroutine so that launch is quick.) |
292 go initFSTree() | 296 go initFSTree() |
293 | 297 |
294 // Immediately update metadata. | 298 // Immediately update metadata. |
295 updateMetadata() | 299 updateMetadata() |
296 // Periodically refresh metadata. | 300 // Periodically refresh metadata. |
297 go refreshMetadataLoop() | 301 go refreshMetadataLoop() |
298 | 302 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 // An httpWriter is an http.ResponseWriter writing to a bytes.Buffer. | 463 // An httpWriter is an http.ResponseWriter writing to a bytes.Buffer. |
460 type httpWriter struct { | 464 type httpWriter struct { |
461 bytes.Buffer | 465 bytes.Buffer |
462 h http.Header | 466 h http.Header |
463 code int | 467 code int |
464 } | 468 } |
465 | 469 |
466 func (w *httpWriter) Header() http.Header { return w.h } | 470 func (w *httpWriter) Header() http.Header { return w.h } |
467 func (w *httpWriter) WriteHeader(code int) { w.code = code } | 471 func (w *httpWriter) WriteHeader(code int) { w.code = code } |
468 | 472 |
| 473 // bounceToPlayground forwards the request to play.golang.org. |
| 474 // TODO(adg): implement this stuff locally. |
| 475 func bounceToPlayground(w http.ResponseWriter, req *http.Request) { |
| 476 defer req.Body.Close() |
| 477 req.URL.Scheme = "http" |
| 478 req.URL.Host = "play.golang.org" |
| 479 resp, err := http.Post(req.URL.String(), req.Header.Get("Content-type"),
req.Body) |
| 480 if err != nil { |
| 481 http.Error(w, err.Error(), 500) |
| 482 return |
| 483 } |
| 484 w.WriteHeader(resp.StatusCode) |
| 485 io.Copy(w, resp.Body) |
| 486 resp.Body.Close() |
| 487 } |
| 488 |
469 // disabledHandler serves a 501 "Not Implemented" response. | 489 // disabledHandler serves a 501 "Not Implemented" response. |
470 func disabledHandler(w http.ResponseWriter, r *http.Request) { | 490 func disabledHandler(w http.ResponseWriter, r *http.Request) { |
471 w.WriteHeader(http.StatusNotImplemented) | 491 w.WriteHeader(http.StatusNotImplemented) |
472 fmt.Fprint(w, "This functionality is not available via local godoc.") | 492 fmt.Fprint(w, "This functionality is not available via local godoc.") |
473 } | 493 } |
LEFT | RIGHT |