GitHub - duke-git/lancet: A comprehensive, efficient, and reusable util function library of Go. (original) (raw)

Lancet is a comprehensive, efficient, and reusable util function library of go. Inspired by the java apache common package and lodash.js.

Website | 简体中文

Features

Installation

Note:

  1. For users who use go1.18 and above, it is recommended to install lancet v2.x.x. Cause in v2.x.x all functions were rewritten with generics of go1.18.

go get github.com/duke-git/lancet/v2 // will install latest version of v2.x.x

  1. For users who use version below go1.18, you should install v1.x.x. The latest of v1.x.x is v1.4.6.

go get github.com/duke-git/lancet // below go1.18, install latest version of v1.x.x

Usage

Lancet organizes the code into package structure, and you need to import the corresponding package name when use it. For example, if you use string-related functions,import the strutil package like below:

import "github.com/duke-git/lancet/v2/strutil"

Example

Here takes the string function Reverse (reverse order string) as an example, and the strutil package needs to be imported.

package main

import ( "fmt" "github.com/duke-git/lancet/v2/strutil" )

func main() { s := "hello" rs := strutil.Reverse(s) fmt.Println(rs) //olleh }

Documentation

Index

1. Algorithm package implements some basic algorithm. eg. sort, search. index

import "github.com/duke-git/lancet/v2/algorithm"

Function list:

2. Compare package provides a lightweight comparison function on any type. index

import "github.com/duke-git/lancet/v2/compare"

Function list:

3. Concurrency package contain some functions to support concurrent programming. eg, goroutine, channel, async. index

import "github.com/duke-git/lancet/v2/concurrency"

Function list:

4. Condition package contains some functions for conditional judgment. eg. And, Or, TernaryOperator... index

import "github.com/duke-git/lancet/v2/condition"

Function list:

5. Convertor package contains some functions for data conversion. index

import "github.com/duke-git/lancet/v2/convertor"

Function list:

6. Cryptor package is for data encryption and decryption. index

import "github.com/duke-git/lancet/v2/cryptor"

Function list:

7. Datetime package supports date and time format and compare. index

import "github.com/duke-git/lancet/v2/datetime"

Function list:

import list "github.com/duke-git/lancet/v2/datastructure/list" import copyonwritelist "github.com/duke-git/lancet/v2/datastructure/copyonwritelist" import link "github.com/duke-git/lancet/v2/datastructure/link" import stack "github.com/duke-git/lancet/v2/datastructure/stack" import queue "github.com/duke-git/lancet/v2/datastructure/queue" import set "github.com/duke-git/lancet/v2/datastructure/set" import tree "github.com/duke-git/lancet/v2/datastructure/tree" import heap "github.com/duke-git/lancet/v2/datastructure/heap" import hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap" import optional "github.com/duke-git/lancet/v2/datastructure/optional"

Structure list:

9. EventBus is an event bus used for handling events within an application. Index

import "github.com/duke-git/lancet/v2/eventbus"

Function list:

10. Package enum provides a simple enum implementation. Index

import "github.com/duke-git/lancet/v2/enum"

Function list:

11. Fileutil package implements some basic functions for file operations. index

import "github.com/duke-git/lancet/v2/fileutil"

Function list:

12. Formatter contains some functions for data formatting. index

import "github.com/duke-git/lancet/v2/formatter"

Function list:

13. Function package can control the flow of function execution and support part of functional programming. index

import "github.com/duke-git/lancet/v2/function"

Function list:

14. Maputil package includes some functions to manipulate map. index

import "github.com/duke-git/lancet/v2/maputil"

Function list:

15. Mathutil package implements some functions for math calculation. index

import "github.com/duke-git/lancet/v2/mathutil"

Function list:

16. Netutil package contains functions to get net information and send http request. index

import "github.com/duke-git/lancet/v2/netutil"

Function list:

17. Pointer package contains some util functions to operate go pointer. index

import "github.com/duke-git/lancet/v2/pointer"

Function list:

18. Random package implements some basic functions to generate random int and string. index

import "github.com/duke-git/lancet/v2/random"

Function list:

19. Retry package is for executing a function repeatedly until it was successful or canceled by the context. index

import "github.com/duke-git/lancet/v2/retry"

Function list:

20. Slice contains some functions to manipulate slice. index

import "github.com/duke-git/lancet/v2/slice"

Function list:

21. Stream package implements a sequence of elements supporting sequential and operations. this package is an experiment to explore if stream in go can work as the way java does. its function is very limited. index

import "github.com/duke-git/lancet/v2/stream"

Function list:

22. Structs package provides several high level functions to manipulate struct, tag, and field. index

import "github.com/duke-git/lancet/v2/structs"

Function list:

23. Strutil package contains some functions to manipulate string. index

import "github.com/duke-git/lancet/v2/strutil"

Function list:

24. System package contain some functions about os, runtime, shell command. index

import "github.com/duke-git/lancet/v2/system"

Function list:

25. Tuple package implements tuple data type and some operations on it. index

import "github.com/duke-git/lancet/v2/tuple"

Function list:

26. Validator package contains some functions for data validation. index

import "github.com/duke-git/lancet/v2/validator"

Function list:

27. Xerror package implements helpers for errors. index

import "github.com/duke-git/lancet/v2/xerror"

Function list:

How to Contribute

Contribution Guide

Contributors

Thank you to all the people who contributed to lancet!

Star History

Star History Chart