| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package zpages |
| 5 |
|
| 6 |
import ( |
| 7 |
_ "embed" |
| 8 |
"html/template" |
| 9 |
"io" |
| 10 |
"log" |
| 11 |
) |
| 12 |
|
| 13 |
var ( |
| 14 |
templateFunctions = template.FuncMap{ |
| 15 |
"even": even, |
| 16 |
"getKey": getKey, |
| 17 |
"getValue": getValue, |
| 18 |
} |
| 19 |
|
| 20 |
|
| 21 |
componentHeaderBytes []byte |
| 22 |
componentHeaderTemplate = parseTemplate("component_header", componentHeaderBytes) |
| 23 |
|
| 24 |
|
| 25 |
extensionsTableBytes []byte |
| 26 |
extensionsTableTemplate = parseTemplate("extensions_table", extensionsTableBytes) |
| 27 |
|
| 28 |
|
| 29 |
headerBytes []byte |
| 30 |
headerTemplate = parseTemplate("header", headerBytes) |
| 31 |
|
| 32 |
|
| 33 |
footerBytes []byte |
| 34 |
footerTemplate = parseTemplate("footer", footerBytes) |
| 35 |
|
| 36 |
|
| 37 |
pipelinesTableBytes []byte |
| 38 |
pipelinesTableTemplate = parseTemplate("pipelines_table", pipelinesTableBytes) |
| 39 |
|
| 40 |
|
| 41 |
propertiesTableBytes []byte |
| 42 |
propertiesTableTemplate = parseTemplate("properties_table", propertiesTableBytes) |
| 43 |
|
| 44 |
|
| 45 |
featuresTableBytes []byte |
| 46 |
featuresTableTemplate = parseTemplate("features_table", featuresTableBytes) |
| 47 |
) |
| 48 |
|
| 49 |
func parseTemplate(name string, bytes []byte) *template.Template { |
| 50 |
return template.Must(template.New(name).Funcs(templateFunctions).Parse(string(bytes))) |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
type HeaderData struct { |
| 55 |
Title string |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
func WriteHTMLPageHeader(w io.Writer, hd HeaderData) { |
| 60 |
if err := headerTemplate.Execute(w, hd); err != nil { |
| 61 |
log.Printf("zpages: executing template: %v", err) |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
type SummaryExtensionsTableData struct { |
| 67 |
Rows []SummaryExtensionsTableRowData |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
type SummaryExtensionsTableRowData struct { |
| 72 |
FullName string |
| 73 |
Enabled bool |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
func WriteHTMLExtensionsSummaryTable(w io.Writer, spd SummaryExtensionsTableData) { |
| 79 |
if err := extensionsTableTemplate.Execute(w, spd); err != nil { |
| 80 |
log.Printf("zpages: executing template: %v", err) |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
type SummaryPipelinesTableData struct { |
| 86 |
Rows []SummaryPipelinesTableRowData |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
type SummaryPipelinesTableRowData struct { |
| 91 |
FullName string |
| 92 |
InputType string |
| 93 |
MutatesData bool |
| 94 |
Receivers []string |
| 95 |
Processors []string |
| 96 |
Exporters []string |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
func WriteHTMLPipelinesSummaryTable(w io.Writer, spd SummaryPipelinesTableData) { |
| 102 |
if err := pipelinesTableTemplate.Execute(w, spd); err != nil { |
| 103 |
log.Printf("zpages: executing template: %v", err) |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
type ComponentHeaderData struct { |
| 109 |
Name string |
| 110 |
ComponentEndpoint string |
| 111 |
Link bool |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
func WriteHTMLComponentHeader(w io.Writer, chd ComponentHeaderData) { |
| 116 |
if err := componentHeaderTemplate.Execute(w, chd); err != nil { |
| 117 |
log.Printf("zpages: executing template: %v", err) |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
type PropertiesTableData struct { |
| 123 |
Name string |
| 124 |
Properties [][2]string |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
func WriteHTMLPropertiesTable(w io.Writer, chd PropertiesTableData) { |
| 129 |
if err := propertiesTableTemplate.Execute(w, chd); err != nil { |
| 130 |
log.Printf("zpages: executing template: %v", err) |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
func WriteHTMLPageFooter(w io.Writer) { |
| 136 |
if err := footerTemplate.Execute(w, nil); err != nil { |
| 137 |
log.Printf("zpages: executing template: %v", err) |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
func even(x int) bool { |
| 142 |
return x%2 == 0 |
| 143 |
} |
| 144 |
|
| 145 |
func getKey(row [2]string) string { |
| 146 |
return row[0] |
| 147 |
} |
| 148 |
|
| 149 |
func getValue(row [2]string) string { |
| 150 |
return row[1] |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
type FeatureGateTableData struct { |
| 155 |
Rows []FeatureGateTableRowData |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
type FeatureGateTableRowData struct { |
| 160 |
ID string |
| 161 |
Enabled bool |
| 162 |
Description string |
| 163 |
Stage string |
| 164 |
FromVersion string |
| 165 |
ToVersion string |
| 166 |
ReferenceURL string |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
func WriteHTMLFeaturesTable(w io.Writer, ftd FeatureGateTableData) { |
| 171 |
if err := featuresTableTemplate.Execute(w, ftd); err != nil { |
| 172 |
log.Printf("zpages: executing template: %v", err) |
| 173 |
} |
| 174 |
} |