package comfunc

Import Path
	github.com/gookit/goutil/internal/comfunc (on go.dev)

Dependency Relation
	imports 12 packages, and imported by 4 packages


Package-Level Type Names (total 3)
/* sort by: | */
ConvOption convert options HandlePtr auto convert ptr type(int,float,string) value. eg: *int to int - if true: will use real type try convert. default is false - NOTE: current T type's ptr is default support. if ture: value is nil, will return convert error; if false(default): value is nil, will convert to zero value set custom fallback convert func for not supported type. WithOption set convert option func NewConvOption(optFns ...ConvOptionFn) *ConvOption
ConvOptionFn convert option func func WithUserConvFn(fn comdef.ToStringFunc) ConvOptionFn func NewConvOption(optFns ...ConvOptionFn) *ConvOption func ToStringWith(in any, optFns ...ConvOptionFn) (str string, err error) func (*ConvOption).WithOption(optFns ...ConvOptionFn) func github.com/gookit/goutil/mathutil.ToStringWith(in any, optFns ...ConvOptionFn) (string, error) func github.com/gookit/goutil/strutil.ToStringWith(in any, optFns ...ConvOptionFn) (string, error)
ParseEnvLineOption parse env line options NotInlineComments dont parse inline comments. - default: false. will parse inline comments SkipOnErrorLine skip error line, continue parse next line - False: return error, clear parsed map func ParseEnvLines(text string, opt ParseEnvLineOption) (mp map[string]string, err error)
Package-Level Functions (total 23)
Bool try to convert type to bool
Cmdline build
CurrentShell get current used shell env file. return like: "/bin/zsh" "/bin/bash". if onlyName=true, will return "zsh", "bash"
Environ like os.Environ, but will returns key-value map[string]string data.
ExecCmd an command and return output. Usage: ExecCmd("ls", []string{"-al"})
ExpandHome will parse first `~` as user home dir path.
FormatWithArgs format message with args - only one element, format to string - first is format: fmt.Sprintf(firstElem, fmtAndArgs[1:]...) - all is args: return fmt.Sprint(fmtAndArgs...)
HasShellEnv has shell env check. Usage: HasShellEnv("sh") HasShellEnv("bash")
IsDuration check the string is a duration string.
JoinPaths2 elements, like the filepath.Join()
JoinPaths3 elements, like the filepath.Join()
NewConvOption create a new ConvOption
ParseEnvLines parse simple multiline k-v string to a string-map. Can use to parse simple INI or DOTENV file contents. NOTE: - It's like INI/ENV format contents. - Support comments line starts with: "#", ";", "//" - Support inline comments split with: " #" eg: "name=tom # a comments" - DON'T support submap parse.
ShellExec exec command by shell cmdLine e.g. "ls -al"
ShellQuote quote a string on contains ', ", SPACE. refer strconv.Quote()
SplitKvBySep parse string line to k-v, support parse comments. - rmInlineComments: check and remove inline comments by ' #'
SplitLineToKv parse string line to k-v, not support comments. Example: 'DEBUG=true' => ['DEBUG', 'true'] NOTE: line must contain '=', allow: 'ENV_KEY='
StrToBool parse string to bool. like strconv.ParseBool()
ToBool try to convert type to bool
ToDuration parses a duration string. such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". Diff of time.ParseDuration: - support extends unit d, w at the end of string. such as "1d", "2w". - support extends unit: month, week, day - support long string unit at the end. such as "1hour", "2hours", "3minutes", "4mins", "5days", "1weeks". If the string is not a valid duration string, it will return an error.
ToStringWith try to convert value to string. can with some option func, more see ConvOption.
WithUserConvFn set ConvOption.UserConvFn option
Workdir get
Package-Level Variables (only one)
StrBySprintFn convert any value to string by fmt.Sprint