All Projects → gookit → Goutil

gookit / Goutil

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

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Goutil

Bbo
bbo is a utility library of zero dependencies for javascript. 🍖🌭🍔
Stars: ✭ 227 (+10.73%)
Mutual labels:  utils, tools
Utils.js
Useful JavaScript Functions Collection 一些很实用的JavaScript函数封装集合
Stars: ✭ 121 (-40.98%)
Mutual labels:  utils, tools
Assembly-Lib
A 16-bits x86 DOS Assembly library that provides many useful functions for developing programs. It has both VGA grapics functions as well as general purpose utilities. The main purpose of this library was to be able to implement simple DOS games (in Assembly) using VGA (320x200, 256 colors) display.
Stars: ✭ 36 (-82.44%)
Mutual labels:  utils, strings
Ramda Extension
🤘Utility library for functional JavaScript. With ❤️ to Ramda.
Stars: ✭ 139 (-32.2%)
Mutual labels:  utils, tools
Utils Everywhere
整理并收集各种常用的覆盖面广的工具类
Stars: ✭ 329 (+60.49%)
Mutual labels:  utils, tools
Rxtool
Android开发人员不得不收集的工具类集合 | 支付宝支付 | 微信支付(统一下单) | 微信分享 | Zip4j压缩(支持分卷压缩与加密) | 一键集成UCrop选择圆形头像 | 一键集成二维码和条形码的扫描与生成 | 常用Dialog | WebView的封装可播放视频 | 仿斗鱼滑动验证码 | Toast封装 | 震动 | GPS | Location定位 | 图片缩放 | Exif 图片添加地理位置信息(经纬度) | 蛛网等级 | 颜色选择器 | ArcGis | VTPK | 编译运行一下说不定会找到惊喜
Stars: ✭ 11,567 (+5542.44%)
Mutual labels:  utils, tools
Presentation
No need to switch to Power Point anymore.
Stars: ✭ 189 (-7.8%)
Mutual labels:  tools
Bilibili Tools
python实现的bilibili主站助手
Stars: ✭ 195 (-4.88%)
Mutual labels:  tools
Vcspull
🔄 synchronize projects via yaml/json manifest. built on libvcs
Stars: ✭ 187 (-8.78%)
Mutual labels:  cli-utilities
Awesome Devtools
🤖 A curated list of in-browser bookmarklets, tools, and resources for modern full-stack software engineers.
Stars: ✭ 184 (-10.24%)
Mutual labels:  tools
Cambada
Packager for Clojure based on deps.edn (AKA tools.deps). Supporting jar, uberjar and GraalVM's native-image.
Stars: ✭ 207 (+0.98%)
Mutual labels:  tools
Zbn
安全编排与自动化响应平台
Stars: ✭ 201 (-1.95%)
Mutual labels:  tools
Kubernetes Icons
[obsolete] Set of icons for Kubernetes diagrams, has been merged into official k8s repo!!
Stars: ✭ 194 (-5.37%)
Mutual labels:  tools
Yasha
A command-line tool to render Jinja templates for great good
Stars: ✭ 189 (-7.8%)
Mutual labels:  cli-utilities
Websites And Tools
🔰 分类收藏一些网站、工具和软件,记录一些关于 windows/macOS/linux 系统的使用技巧和软件操作。
Stars: ✭ 196 (-4.39%)
Mutual labels:  tools
Android Studio Plugins
This is a list of all awesome and useful android studio plugins.
Stars: ✭ 2,186 (+966.34%)
Mutual labels:  tools
Util
A collection of useful utility functions
Stars: ✭ 201 (-1.95%)
Mutual labels:  strings
Powerlevel9k
Powerlevel9k was a tool for building a beautiful and highly functional CLI, customized for you. P9k had a substantial impact on CLI UX, and its legacy is now continued by P10k.
Stars: ✭ 13,268 (+6372.2%)
Mutual labels:  tools
Scrna Tools
Table of software for the analysis of single-cell RNA-seq data.
Stars: ✭ 193 (-5.85%)
Mutual labels:  tools
Js Refactor
JS Refactoring tool for Visual Studio Code
Stars: ✭ 195 (-4.88%)
Mutual labels:  tools

Go Util

GitHub go.mod Go version GitHub tag (latest SemVer) GoDoc Go Report Card Unit-Tests Build Status Coverage Status

💪 Useful utils for the Go: string, array/slice, map, format, CLI, ENV, filesystem, testing and more.

  • arrutil array/slice util functions
  • dump Simple variable printing tool, printing slice, map will automatically wrap each element and display the call location
  • cliutil CLI util functions
  • envutil ENV util for check current runtime env information
  • fmtutil format data util functions
  • fsutil filesystem util functions
  • jsonutil JSON util functions
  • maputil map util functions
  • mathutil math util functions
  • netutil network util functions
  • strutil string util functions
  • testutil test help util functions

中文说明

GoDoc

Packages

Array/Slice

Package github.com/gookit/goutil/arrutil

// source at arrutil/arrutil.go
func Contains(arr, val interface{}) bool
func NotContains(arr, val interface{}) bool
func GetRandomOne(arr interface{}) interface{}
// source at arrutil/slice.go
func Reverse(ss []string)
func StringsRemove(ss []string, s string) []string
func StringsToInts(ss []string) (ints []int, err error)
func TrimStrings(ss []string, cutSet ...string) (ns []string)
func IntsHas(ints []int, val int) bool
func Int64sHas(ints []int64, val int64) bool
func StringsHas(ss []string, val string) bool

CLI

Package github.com/gookit/goutil/cliutil

// source at cliutil/cliutil.go
func QuickExec(cmdLine string, workDir ...string) (string, error)
func ExecCmd(binName string, args []string, workDir ...string) (string, error)
func ExecCommand(binName string, args []string, workDir ...string) (string, error)
func ShellExec(cmdLine string, shells ...string) (string, error)
func CurrentShell(onlyName bool) (path string)
func HasShellEnv(shell string) bool
// source at cliutil/line_parser.go
func StringToOSArgs(line string) []string
func ParseLine(line string) []string
// source at cliutil/read.go
func ReadInput(question string) (string, error)
func ReadLine(question string) (string, error)
func ReadFirst(question string) (string, error)
// source at cliutil/read_nonwin.go
func ReadPassword(question ...string) string

Dump

Package github.com/gookit/goutil/dump

// source at dump/dump.go
func Std() *Dumper
func Reset()
func Config(fn func(*Dumper))
func Print(vs ...interface{})
func Println(vs ...interface{})
func Fprint(w io.Writer, vs ...interface{})
// source at dump/dumper.go
func NewDumper(out io.Writer, skip int) *Dumper

Examples

example code:

package main

import "github.com/gookit/goutil/dump"

// rum demo:
// 	go run ./dump/_examples/demo1.go
func main() {
	otherFunc1()
}

func otherFunc1() {
	dump.P(
		23,
		[]string{"ab", "cd"},
		[]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, // len > 10
		map[string]interface{}{
			"key": "val", "sub": map[string]string{"k": "v"},
		},
		struct {
			ab string
			Cd int
		}{
			"ab", 23,
		},
	)
}

Preview:

nested struct

source code at dump/dumper_test.TestStruct_WithNested

ENV

Package github.com/gookit/goutil/envutil

// source at envutil/envutil.go
func ParseEnvValue(val string) (newVal string)
// source at envutil/get.go
func Getenv(name string, def ...string) string
// source at envutil/info.go
func IsWin() bool
func IsMac() bool
func IsLinux() bool
func IsConsole(out io.Writer) bool
func IsMSys() bool
func HasShellEnv(shell string) bool
func IsSupportColor() bool
func IsSupport256Color() bool
func IsSupportTrueColor() bool

Formatting

Package github.com/gookit/goutil/fmtutil

// source at fmtutil/format.go
func DataSize(bytes uint64) string
func PrettyJSON(v interface{}) (string, error)
func StringsToInts(ss []string) (ints []int, err error)
func ArgsWithSpaces(args []interface{}) (message string)
// source at fmtutil/time.go
func HowLongAgo(sec int64) string

FileSystem

Package github.com/gookit/goutil/fsutil

// source at fsutil/filesystem.go
func PathExists(path string) bool
func IsDir(path string) bool
func FileExists(path string) bool
func IsFile(path string) bool
func IsAbsPath(aPath string) bool
func Mkdir(dirPath string, perm os.FileMode) error
func MustReadFile(filePath string) []byte
func OpenFile(filepath string, flag int, perm os.FileMode) (*os.File, error)
func QuickOpenFile(filepath string) (*os.File, error)
func CreateFile(fpath string, filePerm, dirPerm os.FileMode) (*os.File, error)
func MustCreateFile(filePath string, filePerm, dirPerm os.FileMode) *os.File
func CopyFile(src string, dst string) error
func MustCopyFile(src string, dst string)
func MimeType(path string) (mime string)
func ReaderMimeType(r io.Reader) (mime string)
func IsImageFile(path string) bool
func IsZipFile(filepath string) bool
func Unzip(archive, targetDir string) (err error)
func DeleteIfFileExist(fpath string) error
func FileExt(fpath string) string
func Suffix(fpath string) string
// source at fsutil/finder.go
func EmptyFinder() *FileFinder
func NewFinder(dirPaths []string, filePaths ...string) *FileFinder
func ExtFilterFunc(exts []string, include bool) FileFilterFunc
func SuffixFilterFunc(suffixes []string, include bool) FileFilterFunc
func PathNameFilterFunc(names []string, include bool) FileFilterFunc
func DotFileFilterFunc(include bool) FileFilterFunc
func ModTimeFilterFunc(limitSec int, op rune, include bool) FileFilterFunc
func GlobFilterFunc(patterns []string, include bool) FileFilterFunc
func RegexFilterFunc(pattern string, include bool) FileFilterFunc
func DotDirFilterFunc(include bool) DirFilterFunc
func DirNameFilterFunc(names []string, include bool) DirFilterFunc

JSON

Package github.com/gookit/goutil/jsonutil

// source at jsonutil/jsonutil.go
func WriteFile(filePath string, data interface{}) error
func ReadFile(filePath string, v interface{}) error
func Encode(v interface{}) ([]byte, error)
func Decode(json []byte, v interface{}) error
func Pretty(v interface{}) (string, error)
func StripComments(src string) string

Map

Package github.com/gookit/goutil/maputil

// source at maputil/convert.go
func KeyToLower(src map[string]string) map[string]string
func ToStringMap(src map[string]interface{}) map[string]string
func HttpQueryString(data map[string]interface{}) string
// source at maputil/maputil.go
func MergeStringMap(src, dst map[string]string, ignoreCase bool) map[string]string
func GetByPath(key string, mp map[string]interface{}) (val interface{}, ok bool)
func Keys(mp interface{}) (keys []string)
func Values(mp interface{}) (values []interface{})

Math/Number

Package github.com/gookit/goutil/mathutil

// source at mathutil/convert.go
func Int(in interface{}) (int, error)
func MustInt(in interface{}) int
func ToInt(in interface{}) (iVal int, err error)
func Uint(in interface{}) (uint64, error)
func MustUint(in interface{}) uint64
func ToUint(in interface{}) (u64 uint64, err error)
func Int64(in interface{}) (int64, error)
func MustInt64(in interface{}) int64
func ToInt64(in interface{}) (i64 int64, err error)
func Float(in interface{}) (float64, error)
func ToFloat(in interface{}) (f64 float64, err error)
func MustFloat(in interface{}) float64
// source at mathutil/number.go
func Percent(val, total int) float64
func ElapsedTime(startTime time.Time) string
func DataSize(size uint64) string
func HowLongAgo(sec int64) string
// source at mathutil/random.go
func RandomInt(min, max int) int

String

Package github.com/gookit/goutil/strutil

// source at strutil/encode.go
func Base64(str string) string
func B64Encode(str string) string
func URLEncode(s string) string
func URLDecode(s string) string
// source at strutil/find_similar.go
func NewComparator(src, dst string) *SimilarComparator
func Similarity(s, t string, rate float32) (float32, bool)
// source at strutil/format.go
func Lowercase(s string) string
func Uppercase(s string) string
func UpperWord(s string) string
func LowerFirst(s string) string
func UpperFirst(s string) string
func Snake(s string, sep ...string) string
func SnakeCase(s string, sep ...string) string
func Camel(s string, sep ...string) string
func CamelCase(s string, sep ...string) string
// source at strutil/id.go
func MicroTimeID() string
func MicroTimeHexID() string
// source at strutil/random.go
func Md5(src interface{}) string
func GenMd5(src interface{}) string
func RandomChars(ln int) string
func RandomCharsV2(ln int) string
func RandomCharsV3(ln int) string
func RandomBytes(length int) ([]byte, error)
func RandomString(length int) (string, error)
// source at strutil/strconv.go
func String(val interface{}) (string, error)
func MustString(in interface{}) string
func ToString(val interface{}) (str string, err error)
func ToBool(s string) (bool, error)
func MustBool(s string) bool
func Bool(s string) (bool, error)
func Int(s string) (int, error)
func ToInt(s string) (int, error)
func MustInt(s string) int
func ToInts(s string, sep ...string) ([]int, error)
func ToIntSlice(s string, sep ...string) (ints []int, err error)
func ToArray(s string, sep ...string) []string
func ToSlice(s string, sep ...string) []string
func ToOSArgs(s string) []string
func ToTime(s string, layouts ...string) (t time.Time, err error)
// source at strutil/strutil.go
func IsAlphabet(char uint8) bool
func Trim(s string, cutSet ...string) string
func TrimLeft(s string, cutSet ...string) string
func TrimRight(s string, cutSet ...string) string
func FilterEmail(s string) string
func Split(s, sep string) (ss []string)
func Substr(s string, pos, length int) string
func Padding(s, pad string, length int, pos uint8) string
func PadLeft(s, pad string, length int) string
func PadRight(s, pad string, length int) 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 PrettyJSON(v interface{}) (string, error)
func RenderTemplate(input string, data interface{}, fns template.FuncMap, isFile ...bool) string
func RenderText(input string, data interface{}, fns template.FuncMap, isFile ...bool) string

System

Package github.com/gookit/goutil/sysutil

// source at sysutil/exec.go
func QuickExec(cmdLine string, workDir ...string) (string, error)
func ExecCmd(binName string, args []string, workDir ...string) (string, error)
func ShellExec(cmdStr string, shells ...string) (string, error)
// source at sysutil/sysutil.go
func CurrentShell(onlyName bool) (path string)
func HasShellEnv(shell string) bool
func FindExecutable(binName string) (string, error)
func HasExecutable(binName string) bool
func IsWin() bool
func IsWindows() bool
func IsMac() bool
func IsLinux() bool
func IsMSys() bool
func IsConsole(out io.Writer) bool
// source at sysutil/sysutil_nonwin.go
func Kill(pid int, signal syscall.Signal) error
func ProcessExists(pid int) bool

Testing

Package github.com/gookit/goutil/testutil

// source at testutil/httpmock.go
func NewHttpRequest(method, path string, data *MD) *http.Request
func MockRequest(h http.Handler, method, path string, data *MD) *httptest.ResponseRecorder
// source at testutil/testutil.go
func DiscardStdout() error
func ReadOutput() (s string)
func RewriteStdout()
func RestoreStdout() (s string)
func RewriteStderr()
func RestoreStderr() (s string)
func MockEnvValue(key, val string, fn func(nv string))
func MockEnvValues(kvMap map[string]string, fn func())

Code Check & Testing

gofmt -w -l ./
golint ./...
go test ./...

Gookit packages

  • gookit/ini Go config management, use INI files
  • gookit/rux Simple and fast request router for golang HTTP
  • gookit/gcli Build CLI application, tool library, running CLI commands
  • gookit/slog Lightweight, easy to extend, configurable logging library written in Go
  • gookit/color A command-line color library with true color support, universal API methods and Windows support
  • gookit/event Lightweight event manager and dispatcher implements by Go
  • gookit/cache Generic cache use and cache manager for golang. support File, Memory, Redis, Memcached.
  • gookit/config Go config management. support JSON, YAML, TOML, INI, HCL, ENV and Flags
  • gookit/filter Provide filtering, sanitizing, and conversion of golang data
  • gookit/validate Use for data validation and filtering. support Map, Struct, Form data
  • gookit/goutil Some utils for the Go: string, array/slice, map, format, cli, env, filesystem, test and more
  • More, please see https://github.com/gookit

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].