Find the path to package main by looking at the root Caller.
()
| 37 | |
| 38 | // Find the path to package main by looking at the root Caller. |
| 39 | func findMainPath() string { |
| 40 | pc := make([]uintptr, 100) |
| 41 | n := runtime.Callers(2, pc) |
| 42 | frames := runtime.CallersFrames(pc[:n]) |
| 43 | for { |
| 44 | frame, more := frames.Next() |
| 45 | // Tests won't have package main, instead they have testing.tRunner |
| 46 | if frame.Function == "main.main" || frame.Function == "testing.tRunner" { |
| 47 | return frame.File |
| 48 | } |
| 49 | if !more { |
| 50 | break |
| 51 | } |
| 52 | } |
| 53 | return "" |
| 54 | } |
| 55 | |
| 56 | func installHealthChecker(mux *http.ServeMux) { |
| 57 | // If no health check handler has been installed by this point, add a trivial one. |
searching dependent graphs…