utils

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindFiles

func FindFiles(filePath string, recursive bool) ([]string, error)

Search files in a directory A Simple implementation

func GetCleanYamlBytes

func GetCleanYamlBytes(input []byte) ([]byte, error)

Yaml cleansing such as remove comment in yaml file.

func HomeDir

func HomeDir() string

HomeDir returns the home directory for the current user

func InSlice

func InSlice(haystack []string, niddle string) bool

If a given string in a slice.

func InfoPrint

func InfoPrint(s ...interface{}) error

Generic Print info.

func IsDir

func IsDir(path string) (bool, error)

If given path a directory

func IsUrl

func IsUrl(urlStr string) bool

If given string a url This validate follows RFC standard

func IsUrlRegexp

func IsUrlRegexp(urlStr string) bool

Validate a url by using regexp

func LoadYaml

func LoadYaml(path string) ([]byte, error)

Load yaml file and return clean yaml bytes.

func MsgFormat

func MsgFormat(msg string, msgType MessageType, options ...string) string

Format error message

func Print

func Print(format FormatType, s ...interface{}) error

Print given interface to given format

func RewritePath

func RewritePath(from, match string) string

Rewrite given path by returning from the first occurence of given string

func ScanFiles

func ScanFiles(root string, exit <-chan bool, level int) (<-chan string, <-chan error)

This function provides a fast result ready machanism via feeding the result immediately as soon as the first file found. By default it will scan recursively. You can define The level of the directory if desire. Given level 0 means recursively. Level 1 is only files in given root directory. Level 2 is files in root directory + any files in folders under root. Other levels are so on and so forth. Exist channel provides a machanism for exiting the scan early without creating memory leak.

func StdoutError

func StdoutError(s ...interface{}) error

Print to stdout with error header.

func StdoutInfo

func StdoutInfo(s ...interface{}) error

Print to stdout with info header.

func StdoutWarn

func StdoutWarn(s ...interface{}) error

Print to stdout with warn header.

Types

type FormatType

type FormatType string

Print format types

const (
	FormatYaml FormatType = "yaml"
	FormatJson FormatType = "json"
	FormatCmd  FormatType = "cmd"
)

type MessageType

type MessageType string
const (
	MessageTypeInfo MessageType = "info"

	MessageTypeWarn MessageType = "warn"

	MessageTypeError MessageType = "error"
)

Message types

type StdoutStrFn

type StdoutStrFn func(input interface{}) (string, error)

Function type to output to stdout

func StdoutStrFactory

func StdoutStrFactory(format FormatType) StdoutStrFn

stdout string conversion factory Default to json

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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