tplx

package
v6.7.3 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TemplateFuncMap = template.FuncMap{
	"escape":                    url.PathEscape,
	"unescaped":                 Unescaped,
	"urlconvert":                Urlconvert,
	"timeformat":                Timeformat,
	"timestamp":                 Timestamp,
	"args":                      Args,
	"reReplaceAll":              ReReplaceAll,
	"match":                     regexp.MatchString,
	"toUpper":                   strings.ToUpper,
	"toLower":                   strings.ToLower,
	"contains":                  strings.Contains,
	"humanize":                  Humanize,
	"humanize1024":              Humanize1024,
	"humanizeDuration":          HumanizeDuration,
	"humanizeDurationInterface": HumanizeDurationInterface,
	"humanizePercentage":        HumanizePercentage,
	"humanizePercentageH":       HumanizePercentageH,
	"add":                       Add,
	"sub":                       Subtract,
	"mul":                       Multiply,
	"div":                       Divide,
	"now":                       Now,
	"toString":                  ToString,
	"formatDecimal":             FormatDecimal,
	"first":                     First,
	"label":                     Label,
	"value":                     Value,
	"strvalue":                  StrValue,
	"safeHtml":                  SafeHtml,
	"title":                     Title,
	"graphLink":                 GraphLink,
	"tableLink":                 TableLink,
	"sortByLabel":               SortByLabel,
	"stripPort":                 StripPort,
	"stripDomain":               StripDomain,
	"toTime":                    ToTime,
	"pathPrefix":                PathPrefix,
	"externalURL":               ExternalURL,
	"parseDuration":             ParseDuration,
	"printf":                    Printf,
}

Functions

func Add

func Add(a, b interface{}) (interface{}, error)

Add returns the sum of a and b.

func Args

func Args(args ...interface{}) map[string]interface{}

func Divide

func Divide(a, b interface{}) (interface{}, error)

Divide returns the division of b from a.

func ExternalURL added in v6.7.0

func ExternalURL(externalURL *url.URL) string

func First added in v6.7.0

func First(v queryResult) (*sample, error)

func FormatDecimal added in v6.0.2

func FormatDecimal(s string, n int) string
func GraphLink(expr string) string

func Humanize

func Humanize(s string) string

func Humanize1024

func Humanize1024(s string) string

func HumanizeDuration

func HumanizeDuration(s string) string

func HumanizeDurationFloat64

func HumanizeDurationFloat64(v float64) string

func HumanizeDurationInterface

func HumanizeDurationInterface(i interface{}) string

func HumanizePercentage

func HumanizePercentage(s string) string

func HumanizePercentageH

func HumanizePercentageH(s string) string

func HumanizeTimestamp added in v6.7.0

func HumanizeTimestamp(i interface{}) (string, error)

func Label added in v6.7.0

func Label(label string, s *sample) string

func Match added in v6.7.0

func Match(pattern, s string) (bool, error)

func Multiply

func Multiply(a, b interface{}) (interface{}, error)

Multiply returns the product of a and b.

func Now

func Now() time.Time

func ParseDuration added in v6.7.0

func ParseDuration(d string) (float64, error)

func PathPrefix added in v6.7.0

func PathPrefix(externalURL *url.URL) string

func Printf added in v6.7.0

func Printf(format string, value interface{}) string

func ReReplaceAll

func ReReplaceAll(pattern, repl, text string) string

func ReplaceTemplateUseHtml added in v6.4.0

func ReplaceTemplateUseHtml(name string, templateText string, templateData any) string

ReplaceTemplateUseHtml replaces variables in a template string with values.

It accepts the following parameters:

- name: The name to use when parsing the template

- templateText: The template string containing variables to replace

- templateData: A struct containing fields to replace the variables

It parses the templateText into a template using template.New and template.Parse.

It executes the parsed template with templateData as the data, writing the result to a bytes.Buffer.

Any {{.Field}} variables in templateText are replaced with values from templateData.

If there are any errors parsing or executing the template, they are logged and the original templateText is returned.

The rendered template string is returned on success.

Example usage:

type Data struct {
  Name string
}

data := Data{"John"}

output := ReplaceTemplateUseHtml("mytpl", "Hello {{.Name}}!", data)

func ReplaceTemplateUseText added in v6.4.0

func ReplaceTemplateUseText(name string, templateText string, templateData any) string

func SafeHtml added in v6.7.0

func SafeHtml(text string) template.HTML

func SortByLabel added in v6.7.0

func SortByLabel(label string, v queryResult) queryResult

func StrValue added in v6.7.0

func StrValue(s *sample) string

func StripDomain added in v6.7.0

func StripDomain(hostPort string) string

func StripPort added in v6.7.0

func StripPort(hostPort string) string

func Subtract

func Subtract(a, b interface{}) (interface{}, error)

Subtract returns the difference of b from a.

func TableLink(expr string) string

func Timeformat

func Timeformat(ts int64, pattern ...string) string

func Timestamp

func Timestamp(pattern ...string) string

func Title added in v6.7.0

func Title(s string) string

func ToFloat64

func ToFloat64(val interface{}) (float64, error)

ToFloat64 convert interface to float64

func ToLower added in v6.7.0

func ToLower(s string) string

func ToString

func ToString(v interface{}) string

func ToTime added in v6.7.0

func ToTime(i interface{}) (*time.Time, error)

func ToUpper added in v6.7.0

func ToUpper(s string) string

func Unescaped

func Unescaped(str string) interface{}

func Urlconvert

func Urlconvert(str string) interface{}

func Value added in v6.7.0

func Value(s *sample) float64

Types

This section is empty.

Jump to

Keyboard shortcuts

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