github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/dom/herd/httpd.go (about) 1 package herd 2 3 import ( 4 "fmt" 5 "net" 6 "net/http" 7 8 "github.com/Cloud-Foundations/Dominator/lib/html" 9 ) 10 11 func (herd *Herd) startServer(portNum uint, daemon bool) error { 12 listener, err := net.Listen("tcp", fmt.Sprintf(":%d", portNum)) 13 if err != nil { 14 return err 15 } 16 html.HandleFunc("/", herd.statusHandler) 17 html.HandleFunc("/listReachableSubs", herd.listReachableSubsHandler) 18 html.HandleFunc("/listSubs", herd.listSubsHandler) 19 html.HandleFunc("/showAliveSubs", 20 html.BenchmarkedHandler(herd.showAliveSubsHandler)) 21 html.HandleFunc("/showAllSubs", 22 html.BenchmarkedHandler(herd.showAllSubsHandler)) 23 html.HandleFunc("/showCompliantSubs", 24 html.BenchmarkedHandler(herd.showCompliantSubsHandler)) 25 html.HandleFunc("/showDeviantSubs", 26 html.BenchmarkedHandler(herd.showDeviantSubsHandler)) 27 html.HandleFunc("/showReachableSubs", 28 html.BenchmarkedHandler(herd.showReachableSubsHandler)) 29 html.HandleFunc("/showSub", html.BenchmarkedHandler(herd.showSubHandler)) 30 if daemon { 31 go http.Serve(listener, nil) 32 } else { 33 http.Serve(listener, nil) 34 } 35 return nil 36 } 37 38 func (herd *Herd) addHtmlWriter(htmlWriter HtmlWriter) { 39 herd.htmlWriters = append(herd.htmlWriters, htmlWriter) 40 }