github.com/Cloud-Foundations/Dominator@v0.3.4/lib/html/api.go (about) 1 package html 2 3 import ( 4 "bufio" 5 "io" 6 "net/http" 7 "time" 8 9 "github.com/Cloud-Foundations/Dominator/lib/wsyscall" 10 ) 11 12 type BenchmarkData struct { 13 startRusage wsyscall.Rusage 14 startTime time.Time 15 } 16 type HtmlWriter interface { 17 WriteHtml(writer io.Writer) 18 } 19 20 type TableWriter struct { 21 doHighlighting bool 22 lastBackground string 23 writer io.Writer 24 } 25 26 func BenchmarkedHandler(handler func(io.Writer, 27 *http.Request)) func(http.ResponseWriter, *http.Request) { 28 return benchmarkedHandler(handler) 29 } 30 31 func CreateBenchmarkData() (*BenchmarkData, error) { 32 return createBenchmarkData() 33 } 34 35 func (bd *BenchmarkData) Write(w *bufio.Writer) error { 36 return bd.write(w) 37 } 38 39 func HandleFunc(pattern string, 40 handler func(w http.ResponseWriter, req *http.Request)) { 41 handleFunc(http.DefaultServeMux, pattern, handler) 42 } 43 44 func RegisterHtmlWriterForPattern(pattern, title string, 45 htmlWriter HtmlWriter) { 46 registerHtmlWriterForPattern(pattern, title, htmlWriter) 47 } 48 49 func ServeMuxHandleFunc(serveMux *http.ServeMux, pattern string, 50 handler func(w http.ResponseWriter, req *http.Request)) { 51 handleFunc(serveMux, pattern, handler) 52 } 53 54 func SetSecurityHeaders(w http.ResponseWriter) { 55 setSecurityHeaders(w) 56 } 57 58 func NewTableWriter(writer io.Writer, doHighlighting bool, 59 columns ...string) (*TableWriter, error) { 60 return newTableWriter(writer, doHighlighting, columns) 61 } 62 63 func (tw *TableWriter) Close() error { 64 return tw.close() 65 } 66 67 func (tw *TableWriter) CloseRow() error { 68 return tw.closeRow() 69 } 70 71 func (tw *TableWriter) OpenRow(foreground, background string) error { 72 return tw.openRow(foreground, background) 73 } 74 75 func (tw *TableWriter) WriteData(foreground, data string) error { 76 return tw.writeData(foreground, data) 77 } 78 79 func (tw *TableWriter) WriteRow(foreground, background string, 80 columns ...string) error { 81 return tw.writeRow(foreground, background, columns) 82 } 83 84 func WriteFooter(writer io.Writer) { 85 writeFooter(writer) 86 } 87 88 func WriteHeader(writer io.Writer) { 89 writeHeader(writer, nil, false) 90 } 91 92 func WriteHeaderNoGC(writer io.Writer) { 93 writeHeader(writer, nil, true) 94 } 95 96 func WriteHeaderWithRequest(writer io.Writer, req *http.Request) { 97 writeHeader(writer, req, false) 98 } 99 100 func WriteHeaderWithRequestNoGC(writer io.Writer, req *http.Request) { 101 writeHeader(writer, req, true) 102 }