github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/lib/html/api.go (about) 1 package html 2 3 import ( 4 "io" 5 "net/http" 6 ) 7 8 type HtmlWriter interface { 9 WriteHtml(writer io.Writer) 10 } 11 12 type TableWriter struct { 13 doHighlighting bool 14 lastBackground string 15 writer io.Writer 16 } 17 18 func BenchmarkedHandler(handler func(io.Writer, 19 *http.Request)) func(http.ResponseWriter, *http.Request) { 20 return benchmarkedHandler(handler) 21 } 22 23 func HandleFunc(pattern string, 24 handler func(w http.ResponseWriter, req *http.Request)) { 25 handleFunc(http.DefaultServeMux, pattern, handler) 26 } 27 28 func RegisterHtmlWriterForPattern(pattern, title string, 29 htmlWriter HtmlWriter) { 30 registerHtmlWriterForPattern(pattern, title, htmlWriter) 31 } 32 33 func ServeMuxHandleFunc(serveMux *http.ServeMux, pattern string, 34 handler func(w http.ResponseWriter, req *http.Request)) { 35 handleFunc(serveMux, pattern, handler) 36 } 37 38 func SetSecurityHeaders(w http.ResponseWriter) { 39 setSecurityHeaders(w) 40 } 41 42 func NewTableWriter(writer io.Writer, doHighlighting bool, 43 columns ...string) (*TableWriter, error) { 44 return newTableWriter(writer, doHighlighting, columns) 45 } 46 47 func (tw *TableWriter) CloseRow() error { 48 return tw.closeRow() 49 } 50 51 func (tw *TableWriter) OpenRow(foreground, background string) error { 52 return tw.openRow(foreground, background) 53 } 54 55 func (tw *TableWriter) WriteData(foreground, data string) error { 56 return tw.writeData(foreground, data) 57 } 58 59 func (tw *TableWriter) WriteRow(foreground, background string, 60 columns ...string) error { 61 return tw.writeRow(foreground, background, columns) 62 } 63 64 func WriteFooter(writer io.Writer) { 65 writeFooter(writer) 66 } 67 68 func WriteHeader(writer io.Writer) { 69 writeHeader(writer, nil, false) 70 } 71 72 func WriteHeaderNoGC(writer io.Writer) { 73 writeHeader(writer, nil, true) 74 } 75 76 func WriteHeaderWithRequest(writer io.Writer, req *http.Request) { 77 writeHeader(writer, req, false) 78 } 79 80 func WriteHeaderWithRequestNoGC(writer io.Writer, req *http.Request) { 81 writeHeader(writer, req, true) 82 }