@@ -20,6 +20,7 @@ import (
2020 "net"
2121 "net/http"
2222 _ "net/http/pprof"
23+ "os"
2324 "runtime"
2425 "strings"
2526 "sync"
@@ -30,6 +31,15 @@ import (
3031 "github.com/mattn/go-colorable"
3132)
3233
34+ var rootPage = []byte (`<!DOCTYPE html>
35+ <ul>
36+ <li><a href="/panicparse">/panicparse</a></li>
37+ <li><a href="/debug/pprof/goroutine?debug=2">/debug/pprof/goroutine?debug=2</a></li>
38+ <li><a href="/url1">/url1</a></li>
39+ <li><a href="/url2">/url2</a></li>
40+ </ul>
41+ ` )
42+
3343func main () {
3444 allowremote := flag .Bool ("allowremote" , false , "allows access from non-localhost; implies -wait" )
3545 sleep := flag .Bool ("wait" , false , "sleep instead of crashing" )
@@ -91,10 +101,22 @@ func main() {
91101 } else {
92102 http .HandleFunc ("/panicparse" , webstack .SnapshotHandler )
93103 }
104+ http .HandleFunc ("/" , func (w http.ResponseWriter , req * http.Request ) {
105+ w .Header ().Set ("Content-Type" , "text/html; charset=utf-8" )
106+ _ , _ = w .Write (rootPage )
107+ })
94108 go http .Serve (ln , http .DefaultServeMux )
95109
96110 // Start many clients.
97- url := "http://" + ln .Addr ().String () + "/"
111+ a := ln .Addr ()
112+ url := fmt .Sprintf ("http://%s/" , a )
113+ if * allowremote {
114+ if h , err := os .Hostname (); err == nil {
115+ if t , ok := a .(* net.TCPAddr ); ok {
116+ url = fmt .Sprintf ("http://%s:%d/" , h , t .Port )
117+ }
118+ }
119+ }
98120 for i := 0 ; i < 10 ; i ++ {
99121 internal .GetAsync (url + "url1" )
100122 }
0 commit comments