util

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTemplateByBytes added in v0.1.0

func GetTemplateByBytes(name string, data map[string]interface{}) ([]byte, error)

GetTemplateByBytes returns the parsed template as a byte slice. It returns an error if the template processing fails.

func GetTemplateByString added in v0.1.0

func GetTemplateByString(name string, data map[string]interface{}) (string, error)

GetTemplateByString returns the parsed template as a string. It returns an error if the template processing fails.

func IsCommandAvailable

func IsCommandAvailable(cmd string) bool

IsCommandAvailable checks if a given command is available in the system's PATH. It takes a string argument 'cmd' which represents the command to check. It returns true if the command is found, otherwise false.

func LoadTemplates

func LoadTemplates(files embed.FS) error

LoadTemplates loads all the templates found in the templates directory from the embedded filesystem. It returns an error if reading the directory or parsing any template fails.

func LoadTemplatesFromDir added in v0.16.0

func LoadTemplatesFromDir(dir string) error

LoadTemplatesFromDir loads all the templates found in the specified directory from the filesystem. It returns an error if reading the directory or parsing any template fails.

func NewTemplateByString added in v0.1.0

func NewTemplateByString(format string, data map[string]interface{}) (string, error)

NewTemplateByString parses a template from a string and executes it with the provided data. It returns the resulting string or an error if the template parsing or execution fails.

Types

type Data

type Data map[string]interface{}

Data defines a custom type for the template data.

func ConvertToMap added in v0.2.1

func ConvertToMap(args []string) Data

ConvertToMap takes a slice of strings in the format "key=value" and converts it into a Data map. Each string in the slice is split into a key and value pair using the first occurrence of the "=" character. If a string does not contain the "=" character, it is ignored. The resulting map contains the keys and values from the input slice.

Args:

args ([]string): A slice of strings where each string is in the format "key=value".

Returns:

Data: A map where the keys and values are derived from the input slice.

Jump to

Keyboard shortcuts

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