helpers

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: MIT Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TemplateFuncs = template.FuncMap{

	"trim":                    strings.TrimSpace,
	"trimRightSpace":          trimRightSpace,
	"trimTrailingWhitespaces": trimRightSpace,
	"rpad":                    rpad,
	"quote":                   quote,
	"stripNewlines":           stripNewlines,
	"quoteNewlines":           quoteNewlines,

	"toUpper": strings.ToUpper,
	"toLower": strings.ToLower,

	"replace":       replace,
	"replaceRegexp": replaceRegexp,

	"add": add,
	"sub": sub,
	"div": div,
	"mul": mul,

	"parseFloat": parseFloat,
	"parseInt":   parseInt,

	"currency": currency,

	"padLeft":  padLeft,
	"padRight": padRight,

	"bold":          bold,
	"underline":     underline,
	"italic":        italic,
	"strikethrough": strikethrough,
	"code":          code,
	"codeBlock":     codeBlock,

	"toYaml":      toYaml,
	"indentBlock": indentBlock,
}

TemplateFuncs provides helpers for the standard cobra usage and help templates

Functions

func CancelOnSignal

func CancelOnSignal(ctx context.Context, signal_ os.Signal, cancel func()) error

func CastList added in v0.2.6

func CastList[To any, From any](list []From) ([]To, bool)

CastList casts a list of From objects to To, by casting it to an interface{} in between.

func CastList2 added in v0.2.6

func CastList2[To any, From any](list interface{}) ([]To, bool)

CastList2 attempts even harder to cast a list of From object to To, by checking if we might be dealing with a list masquerading as a interface{}, then a []interface{}, before checking for []To.

func CastMapMember added in v0.2.6

func CastMapMember[To any](m map[string]interface{}, k string) (*To, bool)

func CastStringMap added in v0.2.6

func CastStringMap[To any, From any](m map[string]From) (map[string]To, bool)

func CastToNumberList added in v0.2.6

func CastToNumberList[To Number, From Number](list []From) ([]To, bool)

CastToNumberList casts a list of From objects to To. This is useful for transform between different int types, for example.

func ConvertJSONArrayToYAML added in v0.2.5

func ConvertJSONArrayToYAML(jsonContent string) (string, error)

func ConvertJSONMapToYAML added in v0.2.5

func ConvertJSONMapToYAML(jsonContent string) (string, error)

func ConvertYAMLArrayToJSON added in v0.2.5

func ConvertYAMLArrayToJSON(yamlContent string) (string, error)

func ConvertYAMLMapToJSON added in v0.2.5

func ConvertYAMLMapToJSON(yamlContent string) (string, error)

func CreateHtmlTemplate added in v0.2.7

func CreateHtmlTemplate(name string) *html.Template

func CreateTemplate added in v0.2.5

func CreateTemplate(name string) *template.Template

func InterfaceListToStringList

func InterfaceListToStringList(list []interface{}) []string

func InterfaceToStringList

func InterfaceToStringList(list interface{}) []string

func LoadJSONFile

func LoadJSONFile(path string, target interface{}) error

func LoadYAMLFile

func LoadYAMLFile(path string, target interface{}) error

func RenderHtmlTemplateString added in v0.2.7

func RenderHtmlTemplateString(tmpl string, data interface{}) (string, error)

func RenderTemplate added in v0.2.5

func RenderTemplate(tmpl TemplateExecute, data interface{}) (string, error)

func RenderTemplateFile added in v0.2.5

func RenderTemplateFile(filename string, data interface{}) (string, error)

func RenderTemplateString

func RenderTemplateString(tmpl string, data interface{}) (string, error)

func SetFloatListReflectValue added in v0.2.6

func SetFloatListReflectValue[To Number](value reflect.Value, v interface{}) error

func SetIntListReflectValue added in v0.2.6

func SetIntListReflectValue[To Number](value reflect.Value, v interface{}) error

func SetReflectValue added in v0.2.6

func SetReflectValue(value reflect.Value, v interface{}) error

func StringInSlice

func StringInSlice(needle string, haystack []string) bool

func StructToMap

func StructToMap(i interface{}, lowerCaseKeys bool) map[string]interface{}

Types

type FloatNumber added in v0.2.6

type FloatNumber interface {
	float32 | float64
}

type Number added in v0.2.6

type Number interface {
	int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | uintptr | float32 | float64
}

type SignedInt added in v0.2.6

type SignedInt interface {
	int | int8 | int16 | int32 | int64
}

type TemplateExecute added in v0.2.7

type TemplateExecute interface {
	Execute(wr io.Writer, data any) error
}

type UnsignedInt added in v0.2.6

type UnsignedInt interface {
	uint | uint8 | uint16 | uint32 | uint64 | uintptr
}

Jump to

Keyboard shortcuts

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