template

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2022 License: MPL-2.0 Imports: 10 Imported by: 42

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Opt

type Opt func(*StringTemplate) error

func Function

func Function(name string, f interface{}) Opt

Function allows the user to specify functions for use in the template. If the name provided is a function that already exists in the function map, this will override the previously specified function.

func Template

func Template(rawTemplate string) Opt

type StringTemplate

type StringTemplate struct {
	// contains filtered or unexported fields
}

StringTemplate creates strings based on the provided template. This uses the go templating language, so anything that adheres to that language will function in this struct. There are several custom functions available for use in the template: - random

  • Randomly generated characters. This uses the charset specified in RandomCharset. Must include a length. Example: {{ rand 20 }}

- truncate

  • Truncates the previous value to the specified length. Must include a maximum length. Example: {{ .DisplayName | truncate 10 }}

- truncate_sha256

  • Truncates the previous value to the specified length. If the original length is greater than the length specified, the remaining characters will be sha256 hashed and appended to the end. The hash will be only the first 8 characters The maximum length will be no longer than the length specified. Example: {{ .DisplayName | truncate_sha256 30 }}

- uppercase

  • Uppercases the previous value. Example: {{ .RoleName | uppercase }}

- lowercase

  • Lowercases the previous value. Example: {{ .DisplayName | lowercase }}

- replace

  • Performs a string find & replace Example: {{ .DisplayName | replace - _ }}

- sha256

  • SHA256 hashes the previous value. Example: {{ .DisplayName | sha256 }}

- base64

  • base64 encodes the previous value. Example: {{ .DisplayName | base64 }}

- unix_time

  • Provides the current unix time in seconds. Example: {{ unix_time }}

- unix_time_millis

  • Provides the current unix time in milliseconds. Example: {{ unix_time_millis }}

- timestamp

  • Provides the current time. Must include a standard Go format string

- uuid

  • Generates a UUID Example: {{ uuid }}

func NewTemplate

func NewTemplate(opts ...Opt) (up StringTemplate, err error)

NewTemplate creates a StringTemplate. No arguments are required as this has reasonable defaults for all values. The default template is specified in the DefaultTemplate constant.

func (StringTemplate) Generate

func (up StringTemplate) Generate(data interface{}) (string, error)

Generate based on the provided template

Jump to

Keyboard shortcuts

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