GithubHelp home page GithubHelp logo

tiancheng92 / gf Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 58 KB

Generic Functions For Go 1.18+

Home Page: https://xutiancheng.top/2022/06/17/gf%E5%BA%93%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E.html

License: MIT License

Go 100.00%
generic go golang

gf's Introduction

gf - Generic Functions For Go 1.18+

Build Status Test Status GoDoc Release

  • 注意:部分方法仅可在Go版本大于等于1.18时使用!

什么是gf包?

  • gf包 是一个容纳一些比较常用的函数的库,主要用于简化 Go 编程。

使用方法

go get -u github.com/tiancheng92/gf

gf包方法详解

字符串相关

函数名 描述
StringJoin 字符串拼接(使用strings.Builder以提升性能)
StringToBytes 字符串转[]byte
BytesToString []byte转字符串
StringCreateGzip 对字符串进行gzip压缩
StringParseGzip 对gzip压缩后的字符串进行解压

浮点数相关

  • 注意:以下方法均使用泛型实现,可以用于任意底层类型为float64或float32的类型
函数名 描述
FloatRound 保留浮点数指定位数的小数

切片相关

  • 注意:以下方法均使用泛型实现,可以用于任意类型的数组。
函数名 描述
ArrayDeduplicate 数组去重
ArrayEqual 数组比较
ArrayContains 查询数组是否包含指定元素
ArrayIntersect 两个数组取交集
ArrayUnion 两个数组取并集
ArrayDifference 两个数组取差集
ArrayFilter 使用函数对数组进行过滤(过滤函数签名为:func(any) bool)
ArrayReverse 数组反转
ArrayBubbleSort 数组进行冒泡排序(仅需实现less方法:func (array []any, i, j int) bool)
ArrayInsertionSort 数组进行插入排序(仅需实现less方法:func(array []any, i, j int) bool)
ArrayHeapSort 数组进行堆排序(仅需实现less方法:func(array []any, i, j int) bool)
ArrayQuickSort 数组进行快速排序(仅需实现less方法:func(array []any, i, j int) bool)
ArraySort 数组进行go原生排序(仅需实现less方法:func(array []any, i, j int) bool)
ArraySplit 把一维数组按步长切分为二维数组

URL相关

函数名 描述
UrlFormat 将url格式化(会进行URL合规性检测、冗余字符删除、query参数排序)

Percentile百分位数相关

函数名 描述
Percentile 获取百分位数

Period Time 周期时间相关

函数名 描述
NewPeriodTime 创建周期时间对象
Append 添加时间段
Union 多个时间段取并集
Intersect 多个时间段取交集
Duration 获取总时长

gf's People

Contributors

tiancheng92 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.