github.com/Cloud-Foundations/Dominator@v0.3.4/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("/listImagesForSubs", herd.listImagesForSubsHandler)
    18  	html.HandleFunc("/listReachableSubs", herd.listReachableSubsHandler)
    19  	html.HandleFunc("/listUnreachableSubs", herd.listUnreachableSubsHandler)
    20  	html.HandleFunc("/listSubs", herd.listSubsHandler)
    21  	html.HandleFunc("/showAliveSubs",
    22  		herd.makeShowSubsHandler(selectAliveSub, "alive"))
    23  	html.HandleFunc("/showAllSubs",
    24  		herd.makeShowSubsHandler(selectAll, ""))
    25  	html.HandleFunc("/showCompliantSubs",
    26  		herd.makeShowSubsHandler(selectCompliantSub, "compliant "))
    27  	html.HandleFunc("/showLikelyCompliantSubs",
    28  		herd.makeShowSubsHandler(selectLikelyCompliantSub, "likely compliant "))
    29  	html.HandleFunc("/showDeviantSubs",
    30  		herd.makeShowSubsHandler(selectDeviantSub, "deviant "))
    31  	html.HandleFunc("/showImagesForSubs",
    32  		html.BenchmarkedHandler(herd.showImagesForSubsHandler))
    33  	html.HandleFunc("/showReachableSubs", herd.showReachableSubsHandler)
    34  	html.HandleFunc("/showUnreachableSubs", herd.showUnreachableSubsHandler)
    35  	html.HandleFunc("/showSub", herd.showSubHandler)
    36  	if daemon {
    37  		go http.Serve(listener, nil)
    38  	} else {
    39  		http.Serve(listener, nil)
    40  	}
    41  	return nil
    42  }
    43  
    44  func (herd *Herd) addHtmlWriter(htmlWriter HtmlWriter) {
    45  	herd.htmlWriters = append(herd.htmlWriters, htmlWriter)
    46  }