goutils

module
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2022 License: MIT

README

goutils Build Status Coverage Status

Utility Code for Golang, for better map, slice manipulation and condition handling

Require Go 1.13 or newer

jsonutil

  • JSONTime a common time format, fully compatible with JSON and GORM

  • Traverse recursively traverse json object and generate path

  • TraverseBytes is like Traverse but more efficient if use bytes

sqlutil

  • GetMysqlErrCode get mysql error code, if error is nil or not a mysql error, return 0. compatible with GORM

maps

  • JSON Map: marshal JSON-format string(s) to map(s) in one function

  • Merge: merge maps together

  • Sequence: extract map keys in-order, with corresponding values

Support int32, int64, uint32, uint64, string key maps

slice

  • Apply: apply a function to a slice (like lambda function in other language)

  • Contain: check if a slice contains given element(s)

  • Index: find indexes of given element(s) in a slice

  • Merge: merge slices together (with unique merge option)

  • Reverse: reverse a slice in-place

  • Sort: stable (reverse) sort slices, by length or numerical sequence

  • Unique: convert a slice to a unique slice (i.e. elements are unique)

Support int32, int64, uint32, uint64, string, bytes slices

condition

  • Any, All: judge multiple boolean conditions in one function

  • Ternary: ternary expression

  • Quaternary: quaternary expression

  • HasZeroValue: check if any value is the zero value of its type (e.g. nil, numeric zero)

  • HasNumber, HasLetter: check if a string contains number/letter

License

This project is released under MIT license

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL