helpers

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package helpers are a sub-section of function from defense-unicorn pkg helpers package

Index

Constants

View Source
const (
	// ReadUser is used for any internal file to be read only
	ReadUser = 0400
	// ReadWriteUser is used for any internal file not normally used by the end user or containing sensitive data
	ReadWriteUser = 0600
	// ReadAllWriteUser is used for any non sensitive file intended to be consumed by the end user
	ReadAllWriteUser = 0644
	// ReadWriteExecuteUser is used for any directory or executable not normally used by the end user or containing sensitive data
	ReadWriteExecuteUser = 0700
	// ReadExecuteAllWriteUser is used for any non sensitive directory or executable intended to be consumed by the end user
	ReadExecuteAllWriteUser = 0755
)

Variables

This section is empty.

Functions

func CreateDirectory

func CreateDirectory(path string, mode os.FileMode) error

CreateDirectory creates a directory for the given path and file mode.

func CreateFile

func CreateFile(filepath string) error

CreateFile creates an empty file at the given path.

func CreateParentDirectory

func CreateParentDirectory(destination string) error

CreateParentDirectory creates the parent directory for the given file path.

func CreatePathAndCopy

func CreatePathAndCopy(source string, destination string) error

CreatePathAndCopy creates the parent directory for the given file path and copies the source file to the destination.

func ExtractBasePathFromURL

func ExtractBasePathFromURL(urlStr string) (string, error)

ExtractBasePathFromURL returns filename from URL string

func GetCryptoHash

func GetCryptoHash(data io.ReadCloser, hashName crypto.Hash) (string, error)

GetCryptoHash returns the computed SHA256 Sum of a given file

func GetSHA256Hash

func GetSHA256Hash(data io.ReadCloser) (string, error)

GetSHA256Hash returns the computed SHA256 Sum of a given file

func GetSHA256OfFile

func GetSHA256OfFile(filePath string) (string, error)

GetSHA256OfFile returns the SHA256 hash of the provided file.

func InvalidPath

func InvalidPath(path string) bool

InvalidPath checks if the given path is valid (if it is a permissions error it is there we just don't have access)

func IsDir

func IsDir(path string) bool

IsDir returns true if the given path is a directory.

func IsURL

func IsURL(source string) bool

IsURL is a helper function to check if a URL is valid.

func SHAsMatch

func SHAsMatch(path, expected string) error

SHAsMatch returns an error if the SHA256 hash of the provided file does not match the expected hash.

func Unique

func Unique[T comparable](s []T) (r []T)

Unique returns a new slice with only unique elements.

Types

This section is empty.

Jump to

Keyboard shortcuts

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