utils

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToJSONFast added in v0.1.2

func ConvertToJSONFast(data any) (string, error)

ConvertToJSONFast converts the provided value to a JSON-encoded string using 'ConfigFastest' config and json.Marshal without indents

func ConvertToYAML added in v0.1.2

func ConvertToYAML(data any) (string, error)

ConvertToYAML converts the provided value to a YAML string

func EncodeAsBlock added in v0.1.2

func EncodeAsBlock(val interface{}, blockType string) *hclwrite.Block

func ExecuteShellCommand

func ExecuteShellCommand(ctx context.Context, command string, args []string, options ExecOptions) error

func FileExists

func FileExists(filename string) bool

func GetSystemDir

func GetSystemDir() string

func MapKeyExists added in v0.1.2

func MapKeyExists(m map[string]any, key string) bool

MapKeyExists checks if a key already defined in a map

func PrintError

func PrintError(err error)

PrintError prints errors to std.Output

func PrintErrorToStdError

func PrintErrorToStdError(err error)

PrintErrorToStdError prints errors to std.Error

func PrintErrorToStdErrorAndExit

func PrintErrorToStdErrorAndExit(err error)

PrintErrorToStdErrorAndExit prints errors to std.Error and exits with an error code

func PrintOrWriteToFile

func PrintOrWriteToFile(format string, filePath string, data any, fileMode os.FileMode) error

PrintOrWriteToFile converts the provided value to given format and writes it to the specified file

func ProcessTemplate

func ProcessTemplate(s string, vars map[string]any) (string, error)

func StringInSlice

func StringInSlice(a string, list []string) bool

func StringKeysFromMap added in v0.1.2

func StringKeysFromMap(m map[string]any) []string

StringKeysFromMap returns a slice of sorted string keys from the provided map

Types

type ExecOptions

type ExecOptions struct {
	DryRun           bool
	Env              []string
	WorkingDirectory string
	StdOut           io.Writer
}

type Formatter added in v0.1.2

type Formatter func(w io.Writer, any interface{}) error

func GetFormatter added in v0.2.0

func GetFormatter(format string) Formatter

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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