util

package
v0.40.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendPrefix

func AppendPrefix(prefix string, keys []string) []string

AppendPrefix prepends the given prefix to each key in the slice.

func ArrayShift

func ArrayShift(array *[]string, position int, value string)

ArrayShift inserts a value at the specified position in the array.

func ColorizeDiff

func ColorizeDiff(diff string) string

ColorizeDiff adds ANSI color codes to a diff string. Added lines (+) are green, removed lines (-) are red, and headers (@@) are cyan.

func GenerateDiff

func GenerateDiff(srcPath, destPath string, contextLines int) (string, error)

GenerateDiff generates a unified diff between two files. srcPath is the staged (new) file, destPath is the existing (old) file. contextLines specifies how many lines of context to include around changes.

func IsConfigChanged

func IsConfigChanged(src, dest string) (bool, error)

IsConfigChanged reports whether src and dest config files are equal. Two config files are equal when they have the same file contents and Unix permissions. The owner, group, and mode must match. It returns false in other cases.

This function is optimized to minimize syscalls by short-circuiting on metadata differences (size, mode, uid/gid) before computing MD5 hashes.

func IsDirectory

func IsDirectory(path string) (bool, error)

func IsFileExist

func IsFileExist(fpath string) bool

isFileExist reports whether path exits.

func RecursiveDirsLookup

func RecursiveDirsLookup(root string, pattern string) ([]string, error)

func RecursiveFilesLookup

func RecursiveFilesLookup(root string, pattern string) ([]string, error)

func ValidateFormat

func ValidateFormat(content []byte, format string) error

ValidateFormat validates that the content is valid for the specified format. Supported formats: json, yaml, toml, xml Returns nil if valid, or an error describing the validation failure.

Types

type FileInfo

type FileInfo struct {
	Uid  uint32
	Gid  uint32
	Mode os.FileMode
	Md5  string
}

fileInfo describes a configuration file and is returned by fileStat.

func FileStat

func FileStat(name string) (fi FileInfo, err error)

filestat return a FileInfo describing the named file.

type Nodes

type Nodes []string

Nodes is a custom flag Var representing a list of etcd nodes.

func (*Nodes) Set

func (n *Nodes) Set(node string) error

Set appends the node to the etcd node list.

func (*Nodes) String

func (n *Nodes) String() string

String returns the string representation of a node var.

Jump to

Keyboard shortcuts

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