Open source GO language tool library supporting over 300 commonly used functions

Open source GO language tool library supporting over 300 commonly used functions

2022-10-12 0 510
Resource Number 45286 Last Updated 2025-02-24
¥ 0USD Upgrade VIP
Download Now Matters needing attention
Can't download? Please contact customer service to submit a link error!
Value-added Service: Installation Guide Environment Configuration Secondary Development Template Modification Source Code Installation

This issue recommends a Go language utility library – Lancet.

6b089ae5e57c426980323b7edc72055fnoop.image_

Lancet is a comprehensive, efficient, and reusable Go language tool library. Lancet was inspired by the Java Apache Common package and lodash. js.

characteristic

  • Comprehensive, efficient, and reusable
  • 300+commonly used go tool functions, supporting string, slice, timestamp, net, crypt
  • Only relying on the Go standard library
  • All exported function unit tests have a coverage rate of 100%

install

1. For users using go1.18 and above, it is recommended to install v2. x.x. Because v2. x.x rewrote most of the functions with go1.18 generics.

go get github.com/duke-git/lancet/v2 //安装v2最新版本v2.x.x

2. Users using versions below go1.18 must install v1. x.x. The latest v1 version currently available is v1.2.9.

go get github.com/duke-git/lancet@v1.2.9 // 使用go1.18以下版本, 必须安装v1.x.x版本

usage

Lancet organizes code in a package structure and requires importing the corresponding package name when used. For example, if using string related functions, you need to import the strutil package:

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

Taking the string utility function ReverseStr as an example, we need to import the strutil package:

package main

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

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

Algorithm package

The algorithm package implements some basic algorithms. For example: sort, search, lrucache, etc.

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

Example: BubbleSort

Bubble sort, the parameter comparator needs to be implemented in the package
lancetconstraints.Comparator

Function Signature:

func BubbleSort[T any](slice []T, comparator lancetconstraints.Comparator)

Example:

package main

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

func main() {
    type intComparator struct{}

    func (c *intComparator) Compare(v1 any, v2 any) int {
        val1, _ := v1.(int)
        val2, _ := v2.(int)

        //ascending order
        if val1 < val2 {
            return -1
        } else if val1 > val2 {
            return 1
        }
        return 0
    }

    intSlice := []int{2, 1, 5, 3, 6, 4}
    comparator := &intComparator{}
    algorithm.BubbleSort(intSlice, comparator)

    fmt.Println(intSlice) //[]int{1, 2, 3, 4, 5, 6}
}

And issue the contract

The concurrent package contains some features that support concurrent programming. For example: goroutines, channels, asyncs, etc.

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

Example: NewChannel

Return a Channel pointer instance

Function Signature:

type Channel struct {}
func NewChannel() *Channel

Example:

package main

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

func main() {
    c := concurrency.NewChannel()
}

Converter package

The converter package supports some common data type conversions.

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

Example: ToBool

Convert string to boolean type using strconv ParseBool

Function Signature:

func ToBool(s string) (bool, error)

Example:

package main

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

func main() {
    v1, _ := convertor.ToBool("1")
    fmt.Println(v1) //true

    v2, _ := convertor.ToBool("true")
    fmt.Println(v2) //true

    v3, _ := convertor.ToBool("True")
    fmt.Println(v3) //true

    v4, _ := convertor.ToBool("123")
    fmt.Println(v4) //false
}

Encrypted package

The crypto encryption package supports data encryption and decryption, obtaining md5 and hash values. Supports base64, md5, hmac, AES, DES, RSA.

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

Example: AesEcbEncrypt

Encrypt data using AES ECB algorithm mode The length of parameter ‘key’ is 16, 24, or 32.

Function Signature:

func AesEcbEncrypt(data, key []byte) []byte

Example:

package main

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

func main() {
    data := "hello world"
  	key := "abcdefghijklmnop"
    encrypted := cryptor.AesEcbEncrypt([]byte(data), []byte(key))

    fmt.Println(string(encrypted))
}

—END—

Open source license: MIT

资源下载此资源为免费资源立即下载
Telegram:@John_Software

Disclaimer: This article is published by a third party and represents the views of the author only and has nothing to do with this website. This site does not make any guarantee or commitment to the authenticity, completeness and timeliness of this article and all or part of its content, please readers for reference only, and please verify the relevant content. The publication or republication of articles by this website for the purpose of conveying more information does not mean that it endorses its views or confirms its description, nor does it mean that this website is responsible for its authenticity.

Ictcoder Free source code Open source GO language tool library supporting over 300 commonly used functions https://ictcoder.com/kyym/open-source-go-language-tool-library-supporting-300-commonly-used-functions.html

Share free open-source source code

Q&A
  • 1, automatic: after taking the photo, click the (download) link to download; 2. Manual: After taking the photo, contact the seller to issue it or contact the official to find the developer to ship.
View details
  • 1, the default transaction cycle of the source code: manual delivery of goods for 1-3 days, and the user payment amount will enter the platform guarantee until the completion of the transaction or 3-7 days can be issued, in case of disputes indefinitely extend the collection amount until the dispute is resolved or refunded!
View details
  • 1. Heptalon will permanently archive the process of trading between the two parties and the snapshots of the traded goods to ensure that the transaction is true, effective and safe! 2, Seven PAWS can not guarantee such as "permanent package update", "permanent technical support" and other similar transactions after the merchant commitment, please identify the buyer; 3, in the source code at the same time there is a website demonstration and picture demonstration, and the site is inconsistent with the diagram, the default according to the diagram as the dispute evaluation basis (except for special statements or agreement); 4, in the absence of "no legitimate basis for refund", the commodity written "once sold, no support for refund" and other similar statements, shall be deemed invalid; 5, before the shooting, the transaction content agreed by the two parties on QQ can also be the basis for dispute judgment (agreement and description of the conflict, the agreement shall prevail); 6, because the chat record can be used as the basis for dispute judgment, so when the two sides contact, only communicate with the other party on the QQ and mobile phone number left on the systemhere, in case the other party does not recognize self-commitment. 7, although the probability of disputes is very small, but be sure to retain such important information as chat records, mobile phone messages, etc., in case of disputes, it is convenient for seven PAWS to intervene in rapid processing.
View details
  • 1. As a third-party intermediary platform, Qichou protects the security of the transaction and the rights and interests of both buyers and sellers according to the transaction contract (commodity description, content agreed before the transaction); 2, non-platform online trading projects, any consequences have nothing to do with mutual site; No matter the seller for any reason to require offline transactions, please contact the management report.
View details

Related Article

make a comment
No comments available at the moment
Official customer service team

To solve your worries - 24 hours online professional service