common

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package common contains utility functions for collections, maps and filesystem.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(s []string, str string) bool

Contains returns true if an element is in a slice.

func CopyFileFromEmbeddedFS

func CopyFileFromEmbeddedFS(efs *embed.FS, fs afero.Fs, pathToFile string, saveTo string) error

CopyFileFromEmbeddedFS copy files from the embedded file system to the actual file system.

func Difference added in v0.9.0

func Difference(a, b []string) []string

Difference returns the elements in `a` that aren't in `b`.

func DirExists

func DirExists(fs afero.Fs, path string) bool

DirExists returns true if the directory/folder exists.

func FileExists

func FileExists(fs afero.Fs, path string) (bool, error)

FileExists returns true if the file exists.

func MkDir

func MkDir(fs afero.Fs, x ...string) error

MkDir is a wrapper for afero MkdirAll to create folder structure on the file system.

func MoveFile added in v0.7.0

func MoveFile(efs *embed.FS, fs afero.Fs, sourceFile string, saveTo string, backup bool) error

MoveFile copy files from the embedded file system to the actual file system and can backups them.

func ReadFileLineByLine added in v0.5.2

func ReadFileLineByLine(appFs afero.Fs, filepath string) ([]string, error)

ReadFileLineByLine returns a slice of strings representing lines of the input file.

func RemoveEmpty added in v0.11.0

func RemoveEmpty(s []string) []string

RemoveEmpty delete an empty value in a slice of strings.

func TouchFile

func TouchFile(fs afero.Fs, x ...string) error

TouchFile is used to create a file on the file system.

func Union added in v0.5.2

func Union(a, b []string) []string

Union returns a slice containing the unique values of the input slices.

func UnionMap added in v0.7.0

func UnionMap(m1, m2 map[string]string) map[string]string

UnionMap returns a map joining elements from the inputs.

func Unique added in v0.5.2

func Unique(s []string) []string

Unique removes duplicated entries from a slice of strings.

func WriteToDisk

func WriteToDisk(fs afero.Fs, inpath string, r io.Reader) (err error)

WriteToDisk writes content to a file on the file system. Returns error if something went wrong.

Types

This section is empty.

Jump to

Keyboard shortcuts

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