Documentation ¶
Overview ¶
Package helper implements a few helper functions.
Index ¶
- func BarChart(v []ChartValue, id, label string) template.HTML
- func EscapeCSVLine(input []string) []string
- func GetRealIP(r *http.Request) string
- func PieChart(v []ChartValue, id, label string) template.HTML
- func SanitiseByte(b []byte) template.HTML
- func SanitiseByteClean(b []byte) template.HTML
- func SanitiseReader(r io.Reader) template.HTML
- func SanitiseReaderClean(r io.Reader) template.HTML
- func SanitiseString(s string) template.HTML
- func SanitiseStringClean(s string) template.HTML
- func Stacked100Chart(v [][]int, id string, labelBars []string, LabelValues []string, title string) template.HTML
- type ChartValue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BarChart ¶
func BarChart(v []ChartValue, id, label string) template.HTML
BarChart returns a save HTML fragment of the data as a bar chart. User must embed chart.js.
func EscapeCSVLine ¶
EscapeCSVLine escapes a CSV line (as a []string) so it can be considered save with spreadsheet programs. Escaping is according to https://owasp.org/www-community/attacks/CSV_Injection Please note that since it is assumed the data is written by csv.Writer, escaping that is done by encoding/csv is not performed here (e.g. "-escaping). If you are not using encoding/csv, you have to perform such escaping manually.
func GetRealIP ¶
GetRealIP tries to fing the real IP address of a client. If an error is found, that error will be returned instead of an IP address. A reverse proxy is only assumed if address is a loopback device (to avoid spoofing)
func PieChart ¶
func PieChart(v []ChartValue, id, label string) template.HTML
PieChart returns a save HTML fragment of the data as a pie chart. User must embed chart.js.
func SanitiseByte ¶
SanitiseByte returns a save HTML version of the content provided.
func SanitiseByteClean ¶
SanitiseByteClean returns a save HTML version of the content provided. Most formatting options are stripped.
func SanitiseReader ¶
SanitiseReader returns a save HTML version of the content provided by the reader.
func SanitiseReaderClean ¶
SanitiseReaderClean returns a save HTML version of the content provided by the reader. Most formatting options are stripped.
func SanitiseString ¶
SanitiseString returns a save HTML version of the content provided.
func SanitiseStringClean ¶
SanitiseStringClean returns a save HTML version of the content provided. Most formatting options are stripped.
func Stacked100Chart ¶
func Stacked100Chart(v [][]int, id string, labelBars []string, LabelValues []string, title string) template.HTML
BarChart returns a save HTML fragment of the data as a 100% stacked bar chart. v is interpreted as v[bar][value]. Missing labels wikk be filled with empty labels. User must embed chart.js and chartjs-plugin-stacked100.
Types ¶
type ChartValue ¶
ChartValue represents a single data point in a chart.