Documentation ¶
Overview ¶
string.go - a collection of string related helper functions
Index ¶
- Variables
- func AnyToJsonMarshalIndentSp(data any, endLn bool) *string
- func AnyToJsonMarshalSp(data any, endLn bool) *string
- func BoolStatus(b bool) string
- func BoolString(b bool) string
- func BoolYesNo(b bool) string
- func BoxSealAnonymous(base64PublicKey, msg *string) *string
- func CurrentDirBase() *string
- func CurrentPath() *string
- func DebugEnv() bool
- func DebugLog(msg ...interface{})
- func ErrCheck(e error)
- func FileHasExt(name, ext string) bool
- func FileInDir(dir, filename string) string
- func FileRemoveExt(filename string) string
- func FileSimplifyName(filename string) string
- func FullPath(workPathP *string) *string
- func FullPathStr(workPath string) *string
- func GitExecExist() bool
- func GitExecPath() string
- func GitRemote(workPathP *string, v bool) *[]string
- func GitRemoteExist(workPathP *string, name string) bool
- func GitRemoteRemoveAll(workPathP *string)
- func GitRoot(workPathP *string) string
- func GitRootSubmodule(workPathP *string) string
- func IsDir(workPath string) bool
- func IsRegularFile(workPath string) bool
- func JsonIndentSp(baP *[]byte, endLn bool) *string
- func Report(data any, title string, skipEmpty bool, singleLine bool)
- func ReportDebug(data any, title string, skipEmpty bool, singleLine bool)
- func ReportSp(data any, title string, skipEmpty bool, singleLine bool) *string
- func ReportSpDebug(data any, title string, skipEmpty bool, singleLine bool) *string
- func ReportStatus(data bool, title string, singleLine bool)
- func ReportStatusSp(data bool, title string, singleLine bool) *string
- func SameDir(path1, path2 string) bool
- func StrArrayPtrContain(aP *[]string, sP *string) bool
- func StrArrayPtrPrintln(saP *[]string)
- func StrArrayPtrPrintlnSp(saP *[]string) *string
- func StrArrayPtrRemoveEmpty(saP *[]string) *[]string
- func StrPtrToArrayPtr(sP *string) *[]string
- func StrPtrToJsonIndentSp(strP *string, endLn bool) *string
- func StrToJsonIndentSp(str string, endLn bool) *string
- type Err
- type MyArray
- type MyCmd
- func Git(workPathP *string, optionsP *[]string) *MyCmd
- func GitBranchCurrent(workPathP *string) *MyCmd
- func GitClone(workPathP *string, optionsP *[]string) *MyCmd
- func GitInit(workPathP *string) *MyCmd
- func GitPull(workPathP *string, optionsP *[]string) *MyCmd
- func GitPush(workPathP *string, optionsP *[]string) *MyCmd
- func GitRemoteAdd(workPathP *string, name string, git string) *MyCmd
- func GitRemoteRemove(workPathP *string, name string) *MyCmd
- func MyCmdInit(name string, argsP *[]string, workPathP *string) *MyCmd
- func MyCmdRun(cmdName string, argsP *[]string, workPathP *string) *MyCmd
- func MyCmdRunWg(cmdName string, argsP *[]string, workPathP *string, title *string, ...) *MyCmd
- type ReportT
Constants ¶
This section is empty.
Variables ¶
var Debug bool = false
Debug flag General debug flag to enable/disable ReportDebug*
var DebugReport bool = false
Enable/Disable debug print out within report.go
var NIL_JSON string
nil pointer to string by json.Marshal
var NIL_SPRINT string = fmt.Sprint(nil)
nil pointer to string by sprint
Functions ¶
func AnyToJsonMarshalIndentSp ¶ added in v1.1.3
Json marshal indent format any
- String to json indent format
- If <endLn> is true, add new line at end of string if not exist.
- Return string pointer.
func AnyToJsonMarshalSp ¶ added in v1.1.3
Json marshal format any
- String to json format
- If <endLn> is true, add new line at end of string if not exist.
- Return string pointer.
func BoxSealAnonymous ¶
Encrypt msg with public key using nacl box seal anonymous.
- Parameter "base64PublicKey" and returning string are base64 encoded.
- Return nil if error
- All errors append to Errs
func CurrentDirBase ¶
func CurrentDirBase() *string
Get current directory name. Not full path.
- Return string pointer.
func CurrentPath ¶ added in v0.9.9
func CurrentPath() *string
Get full path of current directory.
- Return string pointer.
func FileHasExt ¶ added in v1.1.3
Check file has supplied extension
func FileInDir ¶ added in v1.1.3
Search for file in a directory
- filename path info removed automatically, only base is used
- case insensitive search
- return actually filename if found
- return empty if not found or error
- error is added to Errs
func FileRemoveExt ¶ added in v1.1.3
Return filename/path with extension removed
func FileSimplifyName ¶ added in v1.1.3
Apply following to filename:
- remove extension
- to lowercase
- remove -,_
func FullPath ¶ added in v1.0.0
Return full path of path provided.
- If <workPathP> is empty/nil, use current path.
- <workPathP> not modified.
- Return string pointer.
func FullPathStr ¶ added in v1.1.3
Return full path of path provided.
- If <workPath> is empty, use current path.
- Return string pointer.
func GitExecPath ¶ added in v0.9.9
func GitExecPath() string
Get git executable path.
- Return empty string if not found.
func GitRemote ¶
Run "git remote".
- If <workPathP> is empty/nil, current directory is used.
- Return remotes in string array.
func GitRemoteExist ¶
Check if a git remote(by name) exist in workPath.
- If <workPathP> is empty/nil, current directory is used.
func GitRemoteRemoveAll ¶
func GitRemoteRemoveAll(workPathP *string)
Run "git remote remove" all git remotes
- If <workPathP> is empty/nil, current directory is used.
func GitRoot ¶ added in v0.9.9
Get git root from current directory.
- If <workPathP> is empty/nil, current directory is used.
- Return empty string if not a git dir.
func GitRootSubmodule ¶ added in v0.9.9
Get git submodule root from `workPath`.
- If <workPathP> is empty/nil, current directory is used.
- Return empty string if not a submodule dir.
func IsRegularFile ¶ added in v1.1.2
Check workPath is regular file
func JsonIndentSp ¶
Json marshal indent format
- If <endLn> is true, add new line at end of string if not exist.
- Return string pointer.
func Report ¶
Print any data(optional) with title(optional).
- If <skipEmpty> is true, will not print title if <data> is empty.
- If <singleLine> is true, <data> will not start on new line.
Refer to ReportT.StringP() for format handling
func ReportDebug ¶
Only print if helper.Debug is true.
- Print any data(optional) with title(optional).
- If <skipEmpty> is true, will not print title if <data> is empty.
- If <singleLine> is true, <data> will not start on new line.
Refer to ReportT.StringP() for format handling
func ReportSp ¶
Print any data(optional) with title(optional) into a string.
- If <skipEmpty> is true, will not print title if <data> is empty.
- If <singleLine> is true, <data> will not start on new line.
- Return a string pointer.
Refer to ReportT.StringP() for format handling
func ReportSpDebug ¶ added in v0.9.8
Only print if helper.Debug is true.
- Print any data(optional) with title(optional) into a string.
- If <skipEmpty> is true, will not print title if <data> is empty.
- If <singleLine> is true, <data> will not start on new line.
- Return a string pointer.
Refer to ReportT.StringP() for format handling
func ReportStatus ¶
Print bool into true/false, with title(optional).
- If <skipEmpty> is true, will not print title if <data> is empty.
- If <singleLine> is true, <data> will not start on new line.
Refer to ReportT.StringP() for format handling
func ReportStatusSp ¶ added in v1.0.1
Only print if helper.Debug is true.
- Print bool into true/false, with title(optional), into a string.
- If <skipEmpty> is true, will not print title if <data> is empty.
- If <singleLine> is true, <data> will not start on new line.
- Return a string pointer.
Refer to ReportT.StringP() for format handling
func StrArrayPtrContain ¶
Check if string array contain a string.
func StrArrayPtrPrintln ¶
func StrArrayPtrPrintln(saP *[]string)
*[]string output, each element followed by "\n"
func StrArrayPtrPrintlnSp ¶ added in v1.0.1
*[]string to *string, each element followed by "\n"
func StrArrayPtrRemoveEmpty ¶
Return a new *[]string with empty lines removed from *[]string.
- Original []string not modified.
func StrPtrToArrayPtr ¶ added in v1.0.0
*string to *[]string, split by "\n"
func StrPtrToJsonIndentSp ¶ added in v1.1.2
Json marshal indent format
- String to json indent format
- If <endLn> is true, add new line at end of string if not exist.
- Return string pointer.
func StrToJsonIndentSp ¶ added in v1.1.2
Json marshal indent format
- String to json indent format
- If <endLn> is true, add new line at end of string if not exist.
- Return string pointer.
Types ¶
type Err ¶ added in v1.1.2
type Err string
Type Err is a string with error interface
type MyArray ¶ added in v1.1.5
type MyArray[T any] []T
type MyCmd ¶
type MyCmd struct { ArgsP *[]string `json:"ArgsP"` // In : Command args CmdLn string `json:"CmdLn"` // Out: Command line CmdName string `json:"CmdName"` // In : Command name Err error `json:"Err"` // Out: run error ExitCode int `json:ExitCode` // Out: Exit Code Ran bool `json:"Ran"` // Out: Set to true by Run() Stderr bytes.Buffer `json:"Stderr"` // Out: Stderr Stdout bytes.Buffer `json:"Stdout"` // Out: Stdout WorkDir string `json:"WorkDir"` // In : Command working dir }
A exec.Cmd wrapper
func Git ¶ added in v1.1.1
Run "git <optionsP>".
- If <workPathP> is empty/nil, current directory is used.
- Return a MyCmd pointer for execution information.
func GitBranchCurrent ¶ added in v1.1.1
Run "git branch --show-current".
- If <workPathP> is empty/nil, current directory is used.
- Return a MyCmd pointer for execution information.
func GitClone ¶ added in v1.1.1
Run "git clone <optionsP>".
- If <workPathP> is empty/nil, current directory is used.
- Return a MyCmd pointer for execution information.
func GitInit ¶
Run "git init".
- If <workPathP> is empty/nil, current directory is used.
- Return a MyCmd pointer for execution information.
func GitPull ¶ added in v1.1.1
Run "git pull <optionsP>".
- If <workPathP> is empty/nil, current directory is used.
- Return a MyCmd pointer for execution information.
func GitPush ¶
Run "git push <optionsP>".
- If <workPathP> is empty/nil, current directory is used.
- Return a MyCmd pointer for execution information.
func GitRemoteAdd ¶
Run "git remote add <name> <git>".
- If <workPathP> is empty/nil, current directory is used.
- Return a MyCmd pointer for execution information.
func GitRemoteRemove ¶
Run "git remote remove".
- If <workPathP> is empty/nil, current directory is used.
- If remote exist Return a MyCmd pointer for execution information.
- If remote does not exit, return nil.(Nothing to remove)
func MyCmdInit ¶ added in v0.9.9
Setup and return MyCmd pointer.
- If <workPathP> is empty/nil, current directory is used.
func MyCmdRunWg ¶
func MyCmdRunWg(cmdName string, argsP *[]string, workPathP *string, title *string, wgP *sync.WaitGroup, output bool) *MyCmd
MyCmd run func wrapper with sync.WaitGroup support.
- If <workPathP> is empty/nil, current directory is used.
- Print if <output> is true
type ReportT ¶
type ReportT struct { Data any `json:"Data"` // Data to be printed Title string `json:"Title"` // Title of print out ModeStatus bool `json:"ModeStatus"` // bool to "OK/Failed" SkipEmpty bool `json:"SkipEmpty"` // - Return empty string if Data is empty SingleLine bool `json:"SingleLine"` // No need line after title }
ReportT is the base structure for the Report.StringP() function, which support printing a wide range of data types.
func ReportNew ¶
Setup ReportT with data(optional/nil), title(optional/""), <skipEmpty>, <singleLine>.
- Return the ReportT pointer.
Refer to ReportT.StringP() for format handling
func (*ReportT) String ¶
Print self.Data, self.Title to string
- If self.SkipEmpty is true, will not print self.Title if self.Data is empty.
- If self.SingleLine is true, self.Data will not start on new line.
Refer to ReportT.StringP() for format handling
func (*ReportT) StringDebug ¶
Only print if helper.Debug is true.
- Print self.Data, self.Title to string
- If self.SkipEmpty is true, will not print self.Title if self.Data is empty.
- If self.SingleLine is true, self.Data will not start on new line.
Refer to ReportT.StringP() for format handling
func (*ReportT) StringP ¶
Print self.Data, self.Title to string pointer
- If self.SkipEmpty is true, will not print self.Title if self.Data is empty.
- If self.SingleLine is true, self.Data will not start on new line.
- self.Data formatting
- []byte, string, Err, MyArray[error], MyArray[string], including array and pointer, are treated as string and processed by StrToJsonIndentSp()/StrPtrToJsonIndentSp()
- MyArray[any] is processed by AnyToJsonMarshalIndentSp()
- int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64, including pointer, are processed by AnyToJsonMarshalSp()
- All pointer types mentioned above, if nil, are treated as empty string
- Others, usually struct, not specified, are processed by AnyToJsonMarshalIndentSp()
func (*ReportT) StringPDebug ¶
Only print if helper.Debug is true.
- Print self.Data, self.Title to string pointer
- If self.SkipEmpty is true, will not print self.Title if self.Data is empty.
- If self.SingleLine is true, self.Data will not start on new line.
Refer to ReportT.StringP() for format handling