commons

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanPath added in v0.2.0

func CleanPath(path string) string

clean Path string

func Contains added in v0.2.0

func Contains[T comparable](arr []T, element T) bool

function to check if an element exists in a slice Example: Contains([]string{"a", "b", "c"}, "b") -> true

func CreateFile

func CreateFile(path string, contents []byte) error

CreateFile creates a file at the given path and writes the contents to the file. It overwrites the file if it already exists.

func Dir added in v0.2.0

func Dir(filePath string) string

Extract Dir path from file path

func EnsureDirExists

func EnsureDirExists(path string) error

EnsureDirExists checks if a directory exists at the given path, and creates it if it doesn't exist.

func FileName added in v0.2.0

func FileName(path string) string

FileName from path

func FilenameWithoutExtension added in v0.2.0

func FilenameWithoutExtension(path string) string

FilenameWithoutExtension from path

func Filter

func Filter[T any](arr []T, filter func(T) bool) []T

func GetMapKeys added in v0.2.0

func GetMapKeys[T any](m map[string]T) []string

func GetMapKeys is to get keys of map storing any type of values Example: GetMapKeys(map[string]int{"a": 1, "b": 2}) -> []string{"a", "b"}

func GitCheckoutBranch added in v0.2.0

func GitCheckoutBranch(directory, name string) error

func GitCheckoutBranch to checkout branch form name

func GitCloneRepository added in v0.2.0

func GitCloneRepository(url, directory string) error

func GitIsValidGitRepository added in v0.2.0

func GitIsValidGitRepository(directory string) bool

func GitPullRepository added in v0.2.0

func GitPullRepository(directory string) error

func GitResetUncommittedChanges added in v0.2.0

func GitResetUncommittedChanges(directory string) error

func Hash added in v0.2.0

func Hash(args ...string) string

func PathExists added in v0.2.0

func PathExists(path string) bool

Path Exists

func PathPrepare added in v0.2.0

func PathPrepare(path string) string

PathPrepare replaces $HOME, $TMP, $CWD with their respective paths

func PrintJson added in v0.2.0

func PrintJson(obj any)

func to PrintJson is a helper function to print a JSON object in a pretty format.

func Walk added in v0.2.0

func Walk(root string, walkFn filepath.WalkFunc) error

Walk walks the file tree rooted at root, calling walkFn for each file or directory in the tree, including root.

Types

type Cache

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

Cache is a simple in-memory cache.

func NewCache

func NewCache() *Cache

NewCache creates a new Cache.

func (*Cache) Delete

func (c *Cache) Delete(key string)

Delete removes a key-value pair from the cache by key.

func (*Cache) Get

func (c *Cache) Get(key string) (interface{}, bool)

Get retrieves a value from the cache by key.

func (*Cache) Has

func (c *Cache) Has(key string) bool

Has checks if a key exists in the cache.

func (*Cache) Set

func (c *Cache) Set(key string, value interface{})

Set adds a key-value pair to the cache.

Jump to

Keyboard shortcuts

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