Skip to content
forked from gookit/goutil

💪 Helper Utils For The Go: string, array/slice, map, format, cli, env, filesystem, test and more. Go 的一些工具函数,格式化,特殊处理,常用信息获取等等

License

Notifications You must be signed in to change notification settings

isgasho/goutil-2

This branch is 1037 commits behind gookit/goutil:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

8478a30 · Sep 13, 2019

History

55 Commits
Sep 6, 2019
Jul 27, 2019
Aug 30, 2019
Aug 3, 2019
Sep 5, 2019
Sep 13, 2019
Feb 17, 2019
Sep 6, 2019
Aug 30, 2019
Dec 20, 2018
Sep 6, 2019
Sep 13, 2019
Sep 5, 2019
Jul 3, 2018
Aug 30, 2019
Jul 3, 2018
Sep 13, 2019
Sep 13, 2019
Aug 4, 2019
Aug 4, 2019
Jul 29, 2019
Jul 29, 2019

Repository files navigation

Go Util

GitHub tag (latest SemVer) GoDoc Go Report Card Build Status Coverage Status

Some utils for the Go: string, array/slice, map, format, cli, env, filesystem, test and more

中文说明

  • arrutil array/slice util
  • dump print debug vars
  • cliutil CLI util
  • envutil ENV util
  • fmtutil format data tool
  • fsutil filesystem util
  • jsonutil JSON util
  • maputil map util
  • mathutil math util
  • netutil network util
  • strutil string util
  • testutil test help util

GoDoc

Packages

Array/Slice

package github.com/gookit/goutil/arrutil

func Reverse(ss []string)
func StringsRemove(ss []string, s string) []string

CLI Util

package github.com/gookit/goutil/cliutil

func CurrentShell(onlyName bool) (path string)
func ExecCmd(binName string, args []string, workDir ...string) (string, error)
func ExecCommand(binName string, args []string, workDir ...string) (string, error)
func HasShellEnv(shell string) bool
func QuickExec(cmdLine string, workDir ...string) (string, error)
func ShellExec(cmdLine string, shells ...string) (string, error)

Dump Util

package github.com/gookit/goutil/dump

func P(vs ...interface{})
func V(vs ...interface{})
func Print(vs ...interface{})

ENV Util

package github.com/gookit/goutil/envutil

func Getenv(name string, def ...string) string
func HasShellEnv(shell string) bool
func IsConsole(out io.Writer) bool
func IsLinux() bool
func IsMSys() bool
func IsMac() bool
func IsSupport256Color() bool
func IsSupportColor() bool
func IsWin() bool
func ParseEnvValue(val string) (newVal string)

Format Util

package github.com/gookit/goutil/fmtutil

func DataSize(bytes uint64) string
func HowLongAgo(sec int64) string

Filesystem Util

package github.com/gookit/goutil/fsutil

func IsAbsPath(path string) bool
func IsDir(path string) bool
func IsFile(path string) bool
func IsZipFile(filepath string) bool
func PathExists(path string) bool
func Unzip(archive, targetDir string) (err error)

JSON Util

package github.com/gookit/goutil/jsonutil

func Decode(json []byte, v interface{}) error
func Encode(v interface{}) ([]byte, error)
func Pretty(v interface{}) (string, error)
func ReadFile(filePath string, v interface{}) error
func WriteFile(filePath string, data interface{}) error
func StripComments(src string) string

Map Util

  • package github.com/gookit/goutil/maputil
func GetByPath(key string, mp map[string]interface{}) (val interface{}, ok bool)
func KeyToLower(src map[string]string) map[string]string
func Keys(mp interface{}) (keys []string)
func MergeStringMap(src, dst map[string]string, ignoreCase bool) map[string]string
func Values(mp interface{}) (values []interface{})

Math Util

package github.com/gookit/goutil/mathutil

func DataSize(size uint64) string
func ElapsedTime(startTime time.Time) string
func HowLongAgo(sec int64) string
func Percent(val, total int) float64

String Util

package github.com/gookit/goutil/strutil

func Base64Encode(src []byte) []byte
func GenMd5(s string) string
func LowerFirst(s string) string
func PadLeft(s, pad string, length int) string
func PadRight(s, pad string, length int) string
func Padding(s, pad string, length int, pos uint8) string
func PrettyJson(v interface{}) (string, error)
func RandomBytes(length int) ([]byte, error)
func RandomString(length int) (string, error)
func RenderTemplate(input string, data interface{}, isFile ...bool) string
func Repeat(s string, times int) string
func RepeatRune(char rune, times int) (chars []rune)
func Replaces(str string, pairs map[string]string) string
func Similarity(s, t string, rate float32) (float32, bool)
func Split(s, sep string) (ss []string)
func Substr(s string, pos, length int) string
func UpperFirst(s string) string
func UpperWord(s string) string

System Util

package github.com/gookit/goutil/sysutil

func CurrentShell(onlyName bool) (path string)
func ExecCmd(binName string, args []string, workDir ...string) (string, error)
func HasShellEnv(shell string) bool
func Kill(pid int, signal syscall.Signal) error
func ProcessExists(pid int) bool
func QuickExec(cmdLine string, workDir ...string) (string, error)
func ShellExec(cmdStr string, shells ...string) (string, error)

Test Util

package github.com/gookit/goutil/testutil

func DiscardStdout() error
func MockEnvValue(key, val string, fn func(nv string))
func MockEnvValues(kvMap map[string]string, fn func())
func MockRequest(h http.Handler, method, path string, data *MD) *httptest.ResponseRecorder
func RestoreStdout() (s string)
func RewriteStdout()

License

MIT

About

💪 Helper Utils For The Go: string, array/slice, map, format, cli, env, filesystem, test and more. Go 的一些工具函数,格式化,特殊处理,常用信息获取等等

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%