| 1 | package workbench |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | "sort" |
| 6 | ) |
| 7 | |
| 8 | |
| 9 | |
| 10 | type routeRegistrar interface { |
| 11 | HandleFunc(string, func(http.ResponseWriter, *http.Request)) |
| 12 | } |
| 13 | type discoverableMux struct { |
| 14 | *http.ServeMux |
| 15 | patterns []string |
| 16 | } |
| 17 | |
| 18 | func newDiscoverableMux() *discoverableMux { return &discoverableMux{ServeMux: http.NewServeMux()} } |
| 19 | func (m *discoverableMux) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) { |
| 20 | m.patterns = append(m.patterns, pattern) |
| 21 | m.ServeMux.HandleFunc(pattern, handler) |
| 22 | } |
| 23 | func (m *discoverableMux) routes() []string { |
| 24 | patterns := append([]string(nil), m.patterns...) |
| 25 | sort.Strings(patterns) |
| 26 | return patterns |
| 27 | } |