utils

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: Apache-2.0 Imports: 24 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 DecodeYaml added in v0.2.1

func DecodeYaml(reader io.Reader, out any) error

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

FileExists checks if file exists and is not a directory

func FromMap added in v0.3.0

func FromMap(data map[string]any, target any) error

func GetSystemDir

func GetSystemDir() string

func IsDir added in v0.2.1

func IsDir(filename string) bool

IsDir Checks if the filename exists and is a directory

func JoinAbsolutePathWithPath added in v0.2.1

func JoinAbsolutePathWithPath(basePath string, providedPath string) (string, error)

JoinAbsolutePathWithPath checks if the provided path is absolute. If the provided path is relative, it joins the base path with the path and returns the absolute path

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 SetExecOptions added in v0.2.1

func SetExecOptions(ctx context.Context, component ExecOptions) context.Context

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

func ToMap added in v0.3.0

func ToMap(data any) (map[string]any, error)

func TrimBasePathFromPath added in v0.2.1

func TrimBasePathFromPath(basePath string, path string) string

TrimBasePathFromPath trims the base path prefix from the path

func Unique added in v0.2.1

func Unique(list []string) []string

Types

type ExecOptions

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

func GetExecOptions added in v0.2.1

func GetExecOptions(ctx context.Context) ExecOptions

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