util

package
v0.0.0-...-9995684 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BRIGHT_GREEN = color.New(color.FgHiGreen, color.Bold)
View Source
var Logger = log.New(os.Stdout, "[boilerplate] ", log.LstdFlags)

A simple logger we can use to get consistent log formatting through out the app

Functions

func ClearTerminal

func ClearTerminal()

Clear the terminal screen in a cross-platform compatible manner

func CommandInstalled

func CommandInstalled(command string) bool

Return true if the OS has the given command installed

func CopyFile

func CopyFile(source string, destination string) error

Copy a file from source to destination

func CopyFolder

func CopyFolder(srcFolder string, targetFolder string) error

Copy all the files and folders in srcFolder to targetFolder.

func GuessMimeType

func GuessMimeType(path string) (string, error)

Guess the mime type for the given file using a variety of heuristics. Under the hood, uses the Unix/Linux file command, if available, and Go's HTTP package otherwise.

func IsDir

func IsDir(path string) bool

Return true if the path points to a directory

func IsTextFile

func IsTextFile(path string) (bool, error)

There is no way to know for sure if a file is text or binary. The best we can do is use various heuristics to guess. The best set of heuristics is in the Unix/Linux file command, so we use that if it's available. Otherwise, we turn to Go's HTTP package. For more info, see: http://stackoverflow.com/q/16760378/483528

func ListContains

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

Return true if the given list of strings (haystack) contains the given string (needle)

func MarshalListOfObjectsToYAML

func MarshalListOfObjectsToYAML(inputList []interface{}) ([]interface{}, error)

MarshalListOfObjectsToYAML will marshal the list of objects to yaml by calling MarshalYAML on every item in the list and return the results as a list. This is useful when building a custom YAML marshaler.

func MergeMaps

func MergeMaps(maps ...map[string]interface{}) map[string]interface{}

Merge all the maps into one. Sadly, Go has no generics, so this is only defined for string to interface maps.

func PathExists

func PathExists(path string) bool

Return true if the path exists

func PromptUserForInput

func PromptUserForInput(prompt string) (string, error)

Prompt the user for text in the CLI. Returns the text entered by the user.

func PromptUserForYesNo

func PromptUserForYesNo(prompt string) (bool, error)

Prompt the user for a yes/no response and return true if they entered yes.

func RunCommandAndGetOutput

func RunCommandAndGetOutput(command string, args ...string) (string, error)

Run the given command return its stdout and stderr as a string

func RunShellCommand

func RunShellCommand(workingDir string, envVars []string, command string, args ...string) error

Run the given shell command with the given environment variables and arguments in the given working directory

func RunShellCommandAndGetOutput

func RunShellCommandAndGetOutput(workingDir string, envVars []string, command string, args ...string) (string, error)

Run the given shell command with the given environment variables and arguments in the given working directory

func ToString

func ToString(value interface{}) string

Convert a single value to its string representation

func ToStringList

func ToStringList(genericList []interface{}) []string

Convert a generic list to a list of strings

func ToStringMap

func ToStringMap(genericMap map[interface{}]interface{}) map[string]string

Convert a generic map to a map from string to string

func ToStringToGenericMap

func ToStringToGenericMap(genericMap map[interface{}]interface{}) map[string]interface{}

Convert a generic map to a map from string to interface

func WriteFileWithSamePermissions

func WriteFileWithSamePermissions(source string, destination string, contents []byte) error

Write a file to the given destination with the given contents using the same permissions as the file at source

Types

type NoSuchFile

type NoSuchFile string

func (NoSuchFile) Error

func (path NoSuchFile) Error() string

type ObjectMarshalingErr

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

ObjectMarshalingErr is returned when there was an error marshaling the given object to yaml.

func (ObjectMarshalingErr) Error

func (err ObjectMarshalingErr) Error() string

type UnmarshalableObjectErr

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

UnmarshalableObjectErr is returned when the given object does not implement Marshaler interface.

func (UnmarshalableObjectErr) Error

func (err UnmarshalableObjectErr) Error() string

Jump to

Keyboard shortcuts

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