pathhelper

package module
v0.0.2-pre Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2020 License: MIT Imports: 11 Imported by: 0

README

pathhelper

path helper utility tool

Git Clone

git clone https://gitlab.com/evatix-go/pathhelper.git

Prerequisites
  • Either add your ssh key to your gitlab account
  • Or, use your access token to clone it.

Installation

go get gitlab.com/evatix-go/pathhelper

Why pathhelper?

Package pathhelper provides an easy and fast way to get your desired OS(operating system) functionality without the hassle of considering the OS you are on, what GO packages you may need to decode a path or simply find out if the path or file exists etc. We have brought features of different packages and injected some new features to make this package a complete solution for obtaining information regarding filepath independent of platform.

Examples

package main

import (
	"fmt"
	"gitlab.com/evatix-go/pathhelper"
	"gitlab.com/evatix-go/pathhelper/pathhelpercore"
)

func main() {
	// Checking if path is empty
	pathhelpercore.IsEmptyPath("") // returns true

	samplePath := "C:\\users\\"

	// Checking if path exists
	exists :=  pathhelper.IsPathExist(samplePath)
	fmt.Println(exists) // returns true if directory or file exist on that path

	// Getting path as URI
	fmt.Println(pathhelper.GetPathAsUri(samplePath, true)) // file:///c:/users

	// Normalize path
	pathToNormalize := "file:///C:/something/otherthing"
	fmt.Println(pathhelper.NormalizePath(pathToNormalize)) // C:\something\otherthing if OS is windows; C:/something/otherthing if OS is Unix
}

Acknowledgement

For this package we have mainly used OS and filepath packages of GO. For testing the package we have used the very convenient package Go Convey.

Notes

Contributors

License

Evatix MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChangeDoubleBackSlash

func ChangeDoubleBackSlash(path, changeSeparator string) string

func ChangeDoubleForwardSlash

func ChangeDoubleForwardSlash(path, changeSeparator string) string

func ChangeSeparator

func ChangeSeparator(path, currentSeparator, changeSeparator string) string

func CreateDirectory

func CreateDirectory(path string, fileMode os.FileMode) *pathhelpercore.DirectoryResult

Create directory and create the final directory

func CreateDirectoryAll

func CreateDirectoryAll(path string, fileMode os.FileMode) *pathhelpercore.DirectoryResult

Create all sub-directories and create the final directory

func GetAbsoluteFromExecutableDirectoryPath

func GetAbsoluteFromExecutableDirectoryPath(relativePath string, isNormalize bool) string

func GetAbsolutePath

func GetAbsolutePath(basePath, relativePath string, isNormalize bool) string

func GetCombinePathFromGoPath

func GetCombinePathFromGoPath(pathConfig *pathhelpercore.PathConfig, givenPaths ...string) string

By defaultPathConfig: Separator = os.PathSeparator IsNormalize = true IsIgnoreEmptyPath = false

func GetCombinedOfNonEmptyPaths

func GetCombinedOfNonEmptyPaths(separator string, paths []string) string

func GetCombinedPath

func GetCombinedPath(separator string, isIgnoreEmptyPath bool, isNormalize bool, paths ...string) string

@isIgnoreEmptyPath if true then ignore empty string (nil, "", or any empty spaces " ")

func GetCombinedPathUsingConfig

func GetCombinedPathUsingConfig(pathConfig *pathhelpercore.PathConfig, paths ...string) string

if pathConfig is nil then pathConfig gets created pathhelpercore.NewDefaultPathConfig() By NewDefaultPathConfig: Separator = os.PathSeparator IsNormalize = true IsIgnoreEmptyPath = false

func GetCompiledPath

func GetCompiledPath(pathTemplate string, compilingMap *map[string]string) string

func GetExecutableDirectory

func GetExecutableDirectory() string

Represents the directory where the application is running from.

func GetExecutablePath

func GetExecutablePath() string

Represents the exact path to the executable file

func GetFileInfoWrapper

func GetFileInfoWrapper(path string) *pathhelpercore.FileInfoWrapper

func GetPathAsUri

func GetPathAsUri(path string, isNormalizePath bool) string

func GetPathFromUri

func GetPathFromUri(path string, isNormalizePath bool) string

GetPathFromUri function takes a path (string) and a bool input and returns a string after removing Uri prefixes (file:///, file://). If bool is set to true any double separator is also removed from returned string

func GetRelativePath

func GetRelativePath(fullPath, basePath string) string

func GetSlug

func GetSlug(path, separatorOfChoice string) string

GetSlug from given path, usages @forbiddenArray to replace with @separatorOfChoice

func GetTempDirectory

func GetTempDirectory() string

func GetVariables

func GetVariables(stringToCheck string) []string

getVariables function takes a string input and identifies every word that begins with "$" in that input string then returns an array of those words. If input has no word starting with "$" then returns nil.

func GoBin

func GoBin() string

Returns env go bin path

func GoPath

func GoPath() string

Reference: https://stackoverflow.com/a/32650077 Returns env go path : os.Getenv(constants.GoPath) or build.Default.GOPATH

func IsDirectoryPath

func IsDirectoryPath(path string) bool

Slow performance used os.FileInfo, TODO: improve performance in future

func IsFilePath

func IsFilePath(path string) bool

func IsGoModuleOn

func IsGoModuleOn() bool

Returns env go bin path

func IsPathExist

func IsPathExist(path string) bool

func IsPathNotExist

func IsPathNotExist(path string) bool

func IsSlug

func IsSlug(path string) bool

func IsUnix

func IsUnix() bool

func IsUnixCase

func IsUnixCase(os enums.OperatingSystem) bool

it returns if not windows

func IsWindows

func IsWindows() bool

func IsWindowsCase

func IsWindowsCase(os enums.OperatingSystem) bool

func NormalizePath

func NormalizePath(givenPath string) string

func NormalizePathUsingSeparator

func NormalizePathUsingSeparator(pathSeparator, givenPath string) string

func NormalizePathUsingSeparatorIf

func NormalizePathUsingSeparatorIf(isNormalize bool, pathSeparator, givenPath string) string

func PathFromEnvVariable

func PathFromEnvVariable(stringToCheck string) string

PathFromEnvVariable function takes a string input and replaces any word that starts with "$" in the input with its expanded path (if exists) and returns the new string.

func RemoveAndFixDoubleSeparatorToFinalSeparator

func RemoveAndFixDoubleSeparatorToFinalSeparator(finalSeparator, path string) string

Replace both double slashes to single slash (// -> /, \\ -> \) and finally all slashes to finalSeparator

func RemoveAndFixDoubleSeparatorToOsSeparator

func RemoveAndFixDoubleSeparatorToOsSeparator(path string) string

Replace both double slashes to single slash (// -> /, \\ -> \) and finally all slashes to os.Separator

func RemoveDoubleUriSeparator

func RemoveDoubleUriSeparator(path, separator string) string

func RemoveFromPath

func RemoveFromPath(pathTemplate string, removingList *[]string, isNormalizePath bool) string

Given removingList array items will be replaced with "" empty string. If pathTemplate is given as empty string or nil or whitespace then returns as is.

func RemovingDoubleBackSlash

func RemovingDoubleBackSlash(path string) string

func RemovingDoubleSlash

func RemovingDoubleSlash(path string) string

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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