lancet

module
v2.1.7 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2022 License: MIT

README


Go version Release GoDoc Go Report Card test codecov License

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

English | 简体中文

Feature

  • 👏 Comprehensive, efficient and reusable.
  • 💪 300+ go util functions, support string, slice, datetime, net, crypt...
  • 💅 Only depend on the go standard library.
  • 🌍 Unit test for every exported function.

Installation

Note:

  1. For users who use go1.18 and above, it is recommended to install lancet v2.x.x. Cause v2.x.x rewrite all functions 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. now latest v1 is v1.3.2.
go get github.com/duke-git/lancet@v1.3.2 // 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
}

API Documentation

lancet API doc Thanks @UvDream for contributing.

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

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

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

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

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

4. Convertor package contains some functions for data convertion.

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

5. Cryptor package is for data encryption and decryption.

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

6. Datetime package supports date and time format and compare.

import "github.com/duke-git/lancet/v2/datetime"
Function list:
import list "github.com/duke-git/lancet/v2/datastructure/list"
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"
Function list:

8. Fileutil package implements some basic functions for file operations.

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

9. Formatter contains some functions for data formatting.

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

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

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

11. Maputil package includes some functions to manipulate map.

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

12. Mathutil package implements some functions for math calculation.

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

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

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

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

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

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

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

16. Slice contains some functions to manipulate slice.

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

17. Strutil package contains some functions to manipulate string.

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

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

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

19. Validator package contains some functions for data validation.

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

20. xerror package implements helpers for errors.

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

How to Contribute

I really appreciate any code commits which make lancet lib powerful. Please follow the rules below to create your pull request.

  1. Fork the repository.
  2. Create your feature branch.
  3. Commit your changes.
  4. Push to the branch
  5. Create new pull request.

Directories

Path Synopsis
Package algorithm contain some basic algorithm functions.
Package algorithm contain some basic algorithm functions.
Package concurrency contain some functions to support concurrent programming.
Package concurrency contain some functions to support concurrent programming.
Package condition contains some functions for conditional judgment.
Package condition contains some functions for conditional judgment.
Package convertor implements some functions to convert data.
Package convertor implements some functions to convert data.
Package cryptor implements some util functions to encrypt and decrypt.
Package cryptor implements some util functions to encrypt and decrypt.
Package datastructure implements some data structure.
Package datastructure implements some data structure.
hashmap
Package datastructure implements some data structure.
Package datastructure implements some data structure.
heap
Package datastructure implements some data structure.
Package datastructure implements some data structure.
list
Package datastructure implements some data structure.
Package datastructure implements some data structure.
set
Package datetime implements some functions to format date and time.
Package datetime implements some functions to format date and time.
Package fileutil implements some basic functions for file operations
Package fileutil implements some basic functions for file operations
Package formatter implements some functions to format string, struct.
Package formatter implements some functions to format string, struct.
Package function implements some functions for control the function execution and some is for functional programming.
Package function implements some functions for control the function execution and some is for functional programming.
Package internal is for internal use.
Package internal is for internal use.
Package lancetconstraints contain some comstomer constraints.
Package lancetconstraints contain some comstomer constraints.
Package maputil includes some functions to manipulate map.
Package maputil includes some functions to manipulate map.
Package mathutil implements some functions for math calculation.
Package mathutil implements some functions for math calculation.
Package netutil implements some basic functions to send http request and get ip info.
Package netutil implements some basic functions to send http request and get ip info.
Package random implements some basic functions to generate random int and string.
Package random implements some basic functions to generate random int and string.
Package retry is for executing a function repeatedly until it was successful or canceled by the context.
Package retry is for executing a function repeatedly until it was successful or canceled by the context.
Package slice implements some functions to manipulate slice.
Package slice implements some functions to manipulate slice.
Package strutil implements some functions to manipulate string.
Package strutil implements some functions to manipulate string.
Package system contain some functions about os, runtime, shell command.
Package system contain some functions about os, runtime, shell command.
Package validator implements some validate function for string.
Package validator implements some validate function for string.
Package xerror implements helpers for errors
Package xerror implements helpers for errors

Jump to

Keyboard shortcuts

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