helper

package
v0.0.0-...-c20b901 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package helper implements a few helper functions.

Index

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

func EscapeCSVLine(input []string) []string

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

func GetRealIP(r *http.Request) string

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

func SanitiseByte(b []byte) template.HTML

SanitiseByte returns a save HTML version of the content provided.

func SanitiseByteClean

func SanitiseByteClean(b []byte) template.HTML

SanitiseByteClean returns a save HTML version of the content provided. Most formatting options are stripped.

func SanitiseReader

func SanitiseReader(r io.Reader) template.HTML

SanitiseReader returns a save HTML version of the content provided by the reader.

func SanitiseReaderClean

func SanitiseReaderClean(r io.Reader) template.HTML

SanitiseReaderClean returns a save HTML version of the content provided by the reader. Most formatting options are stripped.

func SanitiseString

func SanitiseString(s string) template.HTML

SanitiseString returns a save HTML version of the content provided.

func SanitiseStringClean

func SanitiseStringClean(s string) template.HTML

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

type ChartValue struct {
	Label string
	Value float64
}

ChartValue represents a single data point in a chart.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL