Skip to content

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

License

Notifications You must be signed in to change notification settings

WayneJz/goutils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages