💪 Helper Utils For The Go: string, array/slice, map, format, cli, env, filesystem, test and more.

Go Util

GitHub go.mod Go version GitHub tag (latest SemVer) GoDoc Go Report Card Unit-Tests 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 Reverse(ss []string)
func StringsRemove(ss []string, s string) []string
func TrimStrings(ss []string, cutSet ...string) (ns []string)
func GetRandomOne(arr interface{}) interface{}
// source at arrutil/check.go
func IntsHas(ints []int, val int) bool
func Int64sHas(ints []int64, val int64) bool
func StringsHas(ss []string, val string) bool
func HasValue(arr, val interface{}) bool
func Contains(arr, val interface{}) bool
func NotContains(arr, val interface{}) bool
// source at arrutil/convert.go
func ToInt64s(arr interface{})(ret []int64, err error)
func MustToInt64s(arr interface{}) []int64
func SliceToInt64s(arr []interface{}) []int64
func ToStrings(arr interface{})(ret []string, err error)
func MustToStrings(arr interface{}) []string
func SliceToStrings(arr []interface{}) []string
func StringsToInts(ss []string) (ints []int, err error)

CLI

Package github.com/gookit/goutil/cliutil

// source at cliutil/cliutil.go
func LineBuild(binFile string, args []string) string
func BuildLine(binFile string, args []string) string
func String2OSArgs(line string) []string
func StringToOSArgs(line string) []string
func ParseLine(line string) []string
func QuickExec(cmdLine string, workDir ...string) (string, error)
func ExecLine(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/read.go
func ReadInput(question string) (string, error)
func ReadLine(question string) (string, error)
func ReadFirst(question string) (string, error)
func ReadFirstByte(question string) (byte, error)
func ReadFirstRune(question string) (rune, error)
// source at cliutil/read_nonwin.go
func ReadPassword(question ...string) string

Examples

cmdline parse:

package main

import (
	"fmt"

	"github.com/gookit/goutil/cliutil"
	"github.com/gookit/goutil/dump"
)

func main() {
	args := cliutil.ParseLine(`./app top sub --msg "has multi words"`)
	dump.P(args)

	s := cliutil.BuildLine("./myapp", []string{
		"-a", "val0",
		"-m", "this is message",
		"arg0",
	})
	fmt.Println("Build line:", s)
}

output:

PRINT AT github.com/gookit/goutil/cliutil_test.TestParseLine(line_parser_test.go:30)
[]string [ #len=5
  string("./app"), #len=5
  string("top"), #len=3
  string("sub"), #len=3
  string("--msg"), #len=5
  string("has multi words"), #len=15
]

Build line: ./myapp -a val0 -m "this is message" arg0

Dump

Package github.com/gookit/goutil/dump

// source at dump/dump.go
func Std() *Dumper
func Reset()
func Config(fn func(opts *Options))
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
func NewDefaultOptions(out io.Writer, skip int) *Options

Examples

example code:

10 map[string]interface{}{ "key": "val", "sub": map[string]string{"k": "v"}, }, struct { ab string Cd int }{ "ab", 23, }, ) } ">
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 VarParse(str string) string
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 IsWindows() bool
func IsMac() bool
func IsLinux() bool
func IsMSys() bool
func IsWSL() bool
func IsTerminal(fd uintptr) bool
func StdIsTerminal() bool
func IsConsole(out io.Writer) 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/check.go
func Dir(fpath string) string
func Name(fpath string) string
func FileExt(fpath string) string
func Suffix(fpath string) string
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 IsImageFile(path string) bool
func IsZipFile(filepath string) bool
// 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
// source at fsutil/fsutil.go
func OSTempFile(pattern string) (*os.File, error)
func TempFile(dir, pattern string) (*os.File, error)
func OSTempDir(pattern string) (string, error)
func TempDir(dir, pattern string) (string, error)
func ExpandPath(path string) string
func MimeType(path string) (mime string)
func ReaderMimeType(r io.Reader) (mime string)
// source at fsutil/operate.go
func Mkdir(dirPath string, perm os.FileMode) error
func MkParentDir(fpath string) error
func MustReadFile(filePath string) []byte
func ReadExistFile(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 MustRemove(fpath string)
func QuietRemove(fpath string)
func DeleteIfExist(fpath string) error
func DeleteIfFileExist(fpath string) error
func Unzip(archive, targetDir string) (err error)

Examples

files finder:

", fi.ModTime()) }) } ">
package main

import (
	"fmt"
	"os"

	"github.com/gookit/goutil/fsutil"
)

func main() {
	f := fsutil.EmptyFinder()

	f.
		AddDir("./testdata").
		AddFile("finder.go").
		NoDotFile().
		// NoDotDir().
		Find().
		Each(func(filePath string) {
			fmt.Println(filePath)
		})

	fsutil.NewFinder([]string{"./testdata"}).
		AddFile("finder.go").
		NoDotDir().
		EachStat(func(fi os.FileInfo, filePath string) {
			fmt.Println(filePath, "=>", fi.ModTime())
		})
}

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 IsNumeric(c byte) bool
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

Struct

Package github.com/gookit/goutil/structs

// source at structs/alias.go
func NewAliases(checker func(alias string)) *Aliases
// source at structs/tags.go
func ParseTags(v interface{}) error
func ParseReflectTags(v reflect.Value) error

String

Package github.com/gookit/goutil/strutil

// source at strutil/check.go
func IsNumeric(c byte) bool
func IsAlphabet(char uint8) bool
func IsAlphaNum(c uint8) bool
func StrPos(s, sub string) int
func BytePos(s string, bt byte) int
func RunePos(s string, ru rune) int
func IsStartOf(s, sub string) bool
func IsEndOf(s, sub string) bool
func Len(s string) int
func Utf8len(s string) int
func ValidUtf8String(s string) bool
func IsSpace(c byte) bool
func IsSpaceRune(r rune) bool
func IsBlank(s string) bool
func IsBlankBytes(bs []byte) bool
func IsSymbol(r rune) bool
// source at strutil/convert.go
func String(val interface{}) (string, error)
func MustString(in interface{}) string
func ToString(val interface{}) (str string, err error)
func AnyToString(val interface{}, defaultAsErr bool) (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/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/strutil.go
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 RepeatBytes(char byte, times int) (chars []byte)
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 ExecLine(cmdLine string, workDir ...string) (string, error)
func ExecCmd(binName string, args []string, workDir ...string) (string, error)
func ShellExec(cmdLine string, shells ...string) (string, error)
func FindExecutable(binName string) (string, error)
func Executable(binName string) (string, error)
func HasExecutable(binName string) bool
// source at sysutil/sysenv.go
func UserHomeDir() string
func HomeDir() string
func ExpandPath(path string) string
func Hostname() string
func IsWin() bool
func IsWindows() bool
func IsMac() bool
func IsLinux() bool
func IsMSys() bool
func IsConsole(out io.Writer) bool
func IsTerminal(fd uintptr) bool
func StdIsTerminal() bool
func CurrentShell(onlyName bool) (path string)
func HasShellEnv(shell string) bool
func IsShellSpecialVar(c uint8) 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

Owner
Gookit
🧰 Useful libs for the Go(router, console, log, config, cache, event, validate, filter, i18n, respond-data, view-render, DI)
Gookit
Comments
  • Add new functions for arrutil #44

    Add new functions for arrutil #44

    #44

    function | comment | unit tests | benchmark ----|----|----|---- arrutil.TwowaySearch | Find specialized element in a slice forward and backward in the same time, should be more quicker. | yes | no arrutil.Excepts | Produces the set difference of two slice according to a comparer function | yes | no arrutil.Intersects | Produces the intersect of two slice according to a comparer function | yes | no arrutil.Union | Produces the set union of two slice according to a comparer function | yes | no arrutil.Find | Produces the struct/value of a slice according to a predicate function | yes | no arrutil.FindOrDefault | Produce the struct/value f a slice to a predicate function, produce default value when predicate function not match | yes | no arrutil.TakeWhile | Produce the set of a slice according to a predicate function, produce empty slice when predicate function not match | yes | no arrutil.ExceptWhile | Produce the set of a slice except with a predicate function, produce original slice when predicate function not match | yes | no

  • Concurrency issues in  Dumper

    Concurrency issues in Dumper

    System (please complete the following information):

    • OS: linux, macOS
    • GO Version: 1.18
    • Pkg Version: 0.5.5

    Describe the bug

    &fatal error: concurrent map read and map write
    
    
    To see all goroutines, visit https://github.com/maruel/panicparse#gotraceback
    
    1: running
        runtime :0 throw()
    runtime.throw({0x10490cd05, 0x21})
            /usr/local/go/src/runtime/panic.go:1198 +0x54 fp=0x140003dfa70 sp=0x140003dfa40 pc=0x1046d9c34
    runtime.mapaccess2(0x104997d80, 0x1400044c3f0, 0x140003dfaf0)
            /usr/local/go/src/runtime/map.go:469 +0x228 fp=0x140003dfab0 sp=0x140003dfa70 pc=0x1046b31f8
    github.com/gookit/goutil/dump.(*Dumper).checkCyclicRef(0x14000146180, {0x1049f0bd0, 0x1049d2980}, {0x1049d2980, 0x14000384420, 0x199})
            /{$GOPATH}/pkg/mod/github.com/gookit/[email protected]/dump/dumper.go:403 +0x6c fp=0x140003dfb30 sp=0x140003dfab0 pc=0x1047c8bcc
    github.com/gookit/goutil/dump.(*Dumper).printRValue(0x14000146180, {0x1049f0bd0, 0x10497f860}, {0x10497f860, 0x14000384420, 0x16})
            /{$GOPATH}/pkg/mod/github.com/gookit/[email protected]/dump/dumper.go:309 +0x121c fp=0x140003dfeb0 sp=0x140003dfb30 pc=0x1047c799c
    github.com/gookit/goutil/dump.(*Dumper).printOne(0x14000146180, {0x10497f860, 0x14000384420})
            /{$GOPATH}/pkg/mod/github.com/gookit/[email protected]/dump/dumper.go:229 +0x118 fp=0x140003dff30 sp=0x140003dfeb0 pc=0x1047c6718
    github.com/gookit/goutil/dump.(*Dumper).dump(0x14000146180, {0x140003dffa8, 0x1, 0x1})
            /{$GOPATH}/pkg/mod/github.com/gookit/[email protected]/dump/dumper.go:171 +0x120 fp=0x140003dff80 sp=0x140003dff30 pc=0x1047c5e20
    github.com/gookit/goutil/dump.(*Dumper).Println(...)
            /{$GOPATH}/pkg/mod/github.com/gookit/[email protected]/dump/dumper.go:136
    github.com/gookit/goutil/dump.Println(...)
            /{$GOPATH}/pkg/mod/github.com/gookit/[email protected]/dump/dump.go:96
    main.(*SimpleTradeSpi).OnRtnTrade(0x104bdd850, 0x14000384420)
            /{$GOPATH}/sample/main.go:274 +0x5c fp=0x140003dffc0 sp=0x140003dff80 pc=0x10490021c
    runtime.goexit()
            /usr/local/go/src/runtime/asm_arm64.s:1133 +Failed: failed to parse int on line: "runtime.throw({0x10490cd05, 0x21})"
    

    出错位置:

    func (d *Dumper) checkCyclicRef(t reflect.Type, v reflect.Value) (goon bool) {
    	addr := v.UnsafeAddr()
    	vis := visit{addr, t}
    
    	if vd, ok := d.visited[vis]; ok && vd < d.MaxDepth { <------- here
    		d.indentPrint(t.String(), "{(!CYCLIC REFERENCE!)}\n")
    		return false // don't print v again
    	}
    
    	// record
    	d.visited[vis] = d.curDepth
    	return true
    }
    
  • 在windows平台下,编译报错

    在windows平台下,编译报错

    windows平台下,在使用github.com/gookit/color和github.com/gookit/gcli/v2/interact时 ,因为依赖了该包, 报了异常undefined sysutil.IsConsole, sysutil.IsMSys, sysutil.HasShellEnv,启用了go mod,我尝试删除了所有go mod缓存,并且重新编译,但还是报了上述错误。


    查阅了源代码,发现sysutil/sysutil.go文件头部有条 // +build !windows 代码,表示winodws下该文件不会编译,是表示该包只能在非windows下使用吗?

  • filter中的str2time的问题

    filter中的str2time的问题

    package main
    
    import (
    	"fmt"
    	"time"
    
    	"github.com/gin-gonic/gin"
    	"github.com/gin-gonic/gin/binding"
    	"github.com/gookit/goutil/dump"
    	"github.com/gookit/validate"
    )
    
    func main() {
    	binding.Validator = &customValidator{}
    	r := gin.Default()
    	r.POST("/user/list", func(ctx *gin.Context) {
    		var user User
    		err := ctx.ShouldBindJSON(&user)
    		if err != nil {
    			dump.P(err)
    			ctx.String(400, "出错"+err.Error())
    			return
    		}
    		ctx.String(200, fmt.Sprintf("验证通过:%v", user.Time))
    	})
    
    	r.Run(":8080")
    }
    
    type User struct {
    	Time time.Time `json:"time" validate:"required" filter:"str2time"`
    }
    
    type customValidator struct{}
    
    func (c *customValidator) ValidateStruct(ptr interface{}) error {
    	v := validate.Struct(ptr)
    	v.Validate() // do validating
    
    	if v.Errors.Empty() {
    		return nil
    	}
    
    	return v.Errors
    }
    
    func (c *customValidator) Engine() interface{} {
    	return nil
    }
    

    post请求发送json数据

    {"time":"2018-10-16 12:34:01"}
    

    输出结果

    出错parsing time "\"2018-10-16 12:34:01\"" as "\"2006-01-02T15:04:05Z07:00\"": cannot parse " 12:34:01\"" as "T"
    

    为什么不能解析?

    另外在strutil/convert.go代码中

    		// has 'T' eg: "2006-01-02T15:04:05"
    		if strings.ContainsRune(s, 'T') {
    			layout = strings.Replace(layout, " ", "T", -1)
    		}
    
    		// eg: "2006/01/02 15:04:05"
    		if strings.ContainsRune(s, '/') {
    			layout = strings.Replace(layout, "-", "/", -1)
    		}
    

    strings.Replace函数的第2个与第3个参数是不是写反了?

  • Dump: Can dump provide a parameter to control nil/zero not to print?

    Dump: Can dump provide a parameter to control nil/zero not to print?

    Example:

    type T1 struct {
    	T2 *T2
    	T3 *T3
    }
    
    type T2 struct {
    	Name2 string
    }
    
    type T3 struct {
    	Name3 string
    }
    
    func main() {
    	t1 := &T1{
    		T2: &T2{
    			Name2: "xx",
    		},
    	}
    	dump.P(t1)
    }
    

    output:

    PRINT AT main.main(main.go:27)
    &main.T1 {
      T2: &main.T2 {
        Name2: string("xx"), #len=2
      },
      T3: *main.T3<nil>,
    }
    

    i want to ignore T3: *main.T3<nil>

  • Bump honnef.co/go/tools from 0.0.1-2020.1.4 to 0.0.1-2020.1.5

    Bump honnef.co/go/tools from 0.0.1-2020.1.4 to 0.0.1-2020.1.5

    Bumps honnef.co/go/tools from 0.0.1-2020.1.4 to 0.0.1-2020.1.5.

    Commits
    • e6faca5 Version 2020.1.5
    • ce9d960 Add 2020.1.5 release notes
    • e18389c pattern: support matching field lists
    • 276c3dd staticcheck: don't flag nil constants as useless assignments
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Note: This repo was added to Dependabot recently, so you'll receive a maximum of 5 PRs for your first few update runs. Once an update run creates fewer than 5 PRs we'll remove that limit.

    You can always request more updates by clicking Bump now in your Dependabot dashboard.

    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
    • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

    Additionally, you can set the following in your Dependabot dashboard:

    • Update frequency (including time of day and day of week)
    • Pull request limits (per update run and/or open at any time)
    • Out-of-range updates (receive only lockfile updates, if desired)
    • Security updates (receive only security updates, if desired)
  • build(deps): bump golang.org/x/text from 0.4.0 to 0.5.0

    build(deps): bump golang.org/x/text from 0.4.0 to 0.5.0

    Bumps golang.org/x/text from 0.4.0 to 0.5.0.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • build(deps): bump github.com/gookit/color from 1.5.1 to 1.5.2

    build(deps): bump github.com/gookit/color from 1.5.1 to 1.5.2

    Bumps github.com/gookit/color from 1.5.1 to 1.5.2.

    Release notes

    Sourced from github.com/gookit/color's releases.

    v1.5.2

    Change Log

    Refactor

    Fixed

    Update

    Other

    Full Changelog: https://github.com/gookit/color/compare/v1.5.1...v1.5.2

    Commits
    • d0fe513 chore: update some comments code styles
    • ee046fd Update README.zh-CN.md
    • b59a811 Update README.md
    • bf93227 fix: RGBFromString() maybe input overflow int value
    • 1905566 Merge pull request #50 from gookit/dependabot/go_modules/github.com/stretchr/...
    • 1823e0c build(deps): bump github.com/stretchr/testify from 1.7.5 to 1.8.0
    • 0ec8e78 chore: add more docs for detect color level on readme
    • d305f5f chore: update the readme add more HTML like tags usage
    • e12eb6f chore: update the limit go version and update release gh action
    • efc6d3f refactor: update and refactor the color tag parse logic
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • Supports for slices in mapuitl.go

    Supports for slices in mapuitl.go

    I've been seeing and developing an improvement so that the GetByPath function supports access to slice structures.

    I added the following tests in TestGetByPath and they pass successfully.

            //...
    
            v, ok = maputil.GetByPath("key2", mp)
    	assert.True(t, ok)
    	assert.Equal(t, mp["key2"], v)
    
    	v, ok = maputil.GetByPath("key2.0", mp)
    	assert.True(t, ok)
    	assert.Equal(t, "sv1", v)
    
    	v, ok = maputil.GetByPath("key2.1", mp)
    	assert.True(t, ok)
    	assert.Equal(t, "sv2", v)
    
    	v, ok = maputil.GetByPath("key4.0", mp)
    	assert.True(t, ok)
    	assert.Equal(t, 1, v)
    
    	v, ok = maputil.GetByPath("key4.1", mp)
    	assert.True(t, ok)
    	assert.Equal(t, 2, v)
    
    	v, ok = maputil.GetByPath("key5.0", mp)
    	assert.True(t, ok)
    	assert.Equal(t, 1, v)
    
    	v, ok = maputil.GetByPath("key5.1", mp)
    	assert.True(t, ok)
    	assert.Equal(t, "2", v)
    
    	v, ok = maputil.GetByPath("key5.2", mp)
    	assert.True(t, ok)
    	assert.Equal(t, true, v)
    
    	// Out of bound value
    	v, ok = maputil.GetByPath("key2.2", mp)
    	assert.False(t, ok)
    	assert.Nil(t, v)
    
            //...
    
  • Bump github.com/gookit/color from 1.4.0 to 1.4.1

    Bump github.com/gookit/color from 1.4.0 to 1.4.1

    Bumps github.com/gookit/color from 1.4.0 to 1.4.1.

    Commits
    • d37380a update readme
    • bea68e7 up: fallback on terminfo load error, simple detect by TERM value string
    • 350627c up: support disable color by NO_COLOR env
    • 22ba06a add an new method for Style
    • ba01605 update some for examples
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • Bump github.com/gookit/color from 1.3.7 to 1.3.8

    Bump github.com/gookit/color from 1.3.7 to 1.3.8

    Bumps github.com/gookit/color from 1.3.7 to 1.3.8.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • runtime error: makeslice: cap out of range

    runtime error: makeslice: cap out of range

    • OS: linux
    • GO Version: 1.19.3
    • Pkg Version: 0.6.1

    I use dump.Format(ob) where ob is an interface of struct then I have error: runtime error: makeslice: cap out of range

    trace is:

    Screenshot from 2022-12-25 15-12-24

  • feat: get map diff

    feat: get map diff

    Diff get a map record the difference between the two maps.

    The calculation is based on a map change to b map if deleted some field in a map then the field will be returned in result field same key but is nil value.

     a map {"a":"a","b":"b"}
     b map {"b":"b","c":"c"}
     return map {"a":nil,"c":"c"}
    

    close: https://github.com/gookit/goutil/issues/48

  • [proposal] maputil add func diff(amap, bmap) return difference fields

    [proposal] maputil add func diff(amap, bmap) return difference fields

    A recent task was to compare two json strings and find the field that had been modified.

    I converted them into two map[string]interface data and write a func diff(a, b map[string]interface{}) to find the changed fields.

    I'd like PR this func to maputil later. hope it can help more people who need it.

Q2entities - Parse the entities string from a Quake 2 .bsp map file. Written in Go

Q2Entities A simple command-line utility to extract the entities string from a Quake 2 map file. Entities? Binary Space Partitioning maps (.bsp) conta

Apr 9, 2022
Automatically creates & tiles .tmx format maps from a world map interface
Automatically creates & tiles .tmx format maps from a world map interface

Autotile Create tiled maps for an arbitrarily large world space from a simple interface, then add larger objects randomly with simple rules (eg. place

Aug 19, 2022
Leftright - A concurrent map that is optimized for scenarios where reads are more frequent than writes

leftright A concurrent map that is optimized for scenarios where reads are more

Jan 30, 2022
Common utils that need in every development

Utils modules Common utils that need in every development Modules Conversion String IntToString(num int) string Int8ToString(num int8) string Int16ToS

Nov 5, 2021
List-Utils - 🔧 Utilities for maintaining the list of repost sites

SMR List Utils This is a Go CLI tool that helps with managing the StopModReposts blacklist. Install Use GitHub Releases and download binary. Linux Qui

Jan 3, 2022
Go-Utils is a library containing a collection of Golang utilities

Go-Utils is a library containing a collection of Golang utilities

Jun 2, 2022
🍕 Enjoy a slice! A utility library for dealing with slices and maps that focuses on type safety and performance.

?? github.com/elliotchance/pie Enjoy a slice! pie is a library of utility functions for common operations on slices and maps. Quick Start FAQ What are

Dec 30, 2022
gormuuid array field example

gormuuid - Examples An testing repo for https://github.com/ubgo/gormuuid module How to test Install the postgres and create a new database testdb Upda

Oct 20, 2021
Returns an array of Philippine zipcode details given a search key

Returns an array of Philippine zipcode details given a search key

Jan 20, 2022
Tiny Go tool for running multiple functions concurrently and collecting their results into an error slice.

Overview Short for "ConCurrent". Tiny Go tool for running multiple functions concurrently and collecting their results into an error slice. Dependency

Nov 22, 2021
Wrap byte read options with uniform interface for io.Reader and byte slice

nibbler Nibble chunks from Reader streams and slice in a common way Overview This is a golang module that provides an interface for treating a Reader

Dec 23, 2021
Go 1.18 generics based slice and sorts.

genfuncs import "github.com/nwillc/genfuncs" Package genfuncs implements various functions utilizing Go's Generics to help avoid writing boilerplate c

Jan 2, 2023
Go-library that facilitates the usage of .env files

Goenv Golang-library that facilitates the use of .env files. Installation go get github.com/fabioelizandro/goenv Usage Place a .env file in the root

Nov 7, 2021
make slice items unique in go

make slice items unique in go

Jan 20, 2022
Slice conversion between primitive types

sliceconv Sliceconv implements conversions to and from string representations of primitive types on entire slices. The package supports types int, flo

Sep 27, 2022
Go-path - A helper package that provides utilities for parsing and using ipfs paths

go-path is a helper package that provides utilities for parsing and using ipfs paths

Jan 18, 2022
Helper library for full uint64 randomness, pool backed for efficient concurrency

fastrand64-go Helper library for full uint64 randomness, pool backed for efficient concurrency Inspired by https://github.com/valyala/fastrand which i

Dec 5, 2021
tfu is a Terraform helper to update the providers of Terraform

tfu (speak 'TF-up') tfu is a Terraform helper to update the providers of Terraform Works only starting from version Terraform 0.13+ Nothing more nothi

Apr 26, 2022
Little helper to create tar balls of an executable together with its ELF shared library dependencies.

Little helper to create tar balls of an executable together with its ELF shared library dependencies. This is useful for prototyping with gokrazy: htt

Sep 7, 2022