1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-16 18:52:27 +08:00

update text style of readme file

This commit is contained in:
dudaodong
2022-01-17 10:40:41 +08:00
parent c424b88d40
commit f368854b2d
2 changed files with 39 additions and 44 deletions

View File

@@ -1,4 +1,4 @@
<h1 style="width: 100%;">Lancet</h1> # Lancet
<p style="font-size: 18px"> <p style="font-size: 18px">
Lancet is a comprehensive, efficient, and reusable util function library of go. Inspired by the java apache common package and lodash.js. Lancet is a comprehensive, efficient, and reusable util function library of go. Inspired by the java apache common package and lodash.js.
</p> </p>
@@ -15,31 +15,28 @@
English | [简体中文](./README_zh-CN.md) English | [简体中文](./README_zh-CN.md)
### Feature ## Feature
---
- 👏 Comprehensive, efficient and reusable. - 👏 Comprehensive, efficient and reusable.
- 💪 140+ common go util functions, support string, slice, datetime, net, crypt... - 💪 140+ common go util functions, support string, slice, datetime, net, crypt...
- 💅 Only depend on the go standard library. - 💅 Only depend on the go standard library.
- 🌍 Unit test for every exported function. - 🌍 Unit test for every exported function.
### Installation ## Installation
---
```go ```go
go get github.com/duke-git/lancet go get github.com/duke-git/lancet
``` ```
### Usage ## 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: 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:
```go ```go
import "github.com/duke-git/lancet/strutil" import "github.com/duke-git/lancet/strutil"
``` ```
### Example ## Example
---
Here takes the string function ReverseStr (reverse order string) as an example, and the strutil package needs to be imported. Here takes the string function ReverseStr (reverse order string) as an example, and the strutil package needs to be imported.
@@ -58,9 +55,8 @@ func main() {
} }
``` ```
### API Documentation ## API Documentation
--- ### 1. convertor contains some functions for data convertion
#### 1. convertor contains some functions for data convertion
- Support conversion between commonly used data types. - Support conversion between commonly used data types.
- Usage: import "github.com/duke-git/lancet/convertor" - Usage: import "github.com/duke-git/lancet/convertor"
@@ -98,7 +94,7 @@ func ToString(value interface{}) string //convert value to string
func StructToMap(value interface{}) (map[string]interface{}, error) //convert struct to map, only convert exported field, tag `json` should be set func StructToMap(value interface{}) (map[string]interface{}, error) //convert struct to map, only convert exported field, tag `json` should be set
``` ```
#### 2. cryptor is for data encryption and decryption ### 2. cryptor is for data encryption and decryption
- Support md5, hmac, aes, des, ras. - Support md5, hmac, aes, des, ras.
- Usage: import "github.com/duke-git/lancet/cryptor" - Usage: import "github.com/duke-git/lancet/cryptor"
@@ -157,7 +153,7 @@ func RsaDecrypt(data []byte, privateKeyFileName string) []byte //RSA decrypt
``` ```
#### 3. datetime parse and format datetime ### 3. datetime parse and format datetime
- Parse and format datetime - Parse and format datetime
- Usage: import "github.com/duke-git/lancet/datetime" - Usage: import "github.com/duke-git/lancet/datetime"
@@ -192,7 +188,7 @@ func FormatTimeToStr(t time.Time, format string) string //convert time to string
func FormatStrToTime(str, format string) time.Time //convert string to time func FormatStrToTime(str, format string) time.Time //convert string to time
``` ```
#### 4. fileutil basic functions for file operations ### 4. fileutil basic functions for file operations
- Basic functions for file operations. - Basic functions for file operations.
- Usage: import "github.com/duke-git/lancet/fileutil" - Usage: import "github.com/duke-git/lancet/fileutil"
@@ -229,7 +225,7 @@ func Zip(fpath string, destPath string) error //create zip file, fpath could be
func UnZip(zipFile string, destPath string) error //unzip the file and save it to destPath func UnZip(zipFile string, destPath string) error //unzip the file and save it to destPath
``` ```
#### 5. formatter is for data format ### 5. formatter is for data format
- Contain some formatting function - Contain some formatting function
- Usage: import "github.com/duke-git/lancet/formatter" - Usage: import "github.com/duke-git/lancet/formatter"
@@ -254,7 +250,7 @@ func main() {
func Comma(v interface{}, symbol string) string //add comma to number by every 3 numbers from right. ahead by symbol char func Comma(v interface{}, symbol string) string //add comma to number by every 3 numbers from right. ahead by symbol char
``` ```
#### 6. function can control the function execution and support functional programming ### 6. function can control the function execution and support functional programming
- Control function execution and support functional programming. - Control function execution and support functional programming.
- Usage: import "github.com/duke-git/lancet/function" - Usage: import "github.com/duke-git/lancet/function"
@@ -290,7 +286,7 @@ func (w *Watcher) Reset() {} //reset the watch timer.
func (w *Watcher) GetElapsedTime() time.Duration //return time duration from watcher start to end. func (w *Watcher) GetElapsedTime() time.Duration //return time duration from watcher start to end.
``` ```
#### 7. netutil is for net process ### 7. netutil is for net process
- Ip and http request method. - Ip and http request method.
- Usage: import "github.com/duke-git/lancet/netutil". - Usage: import "github.com/duke-git/lancet/netutil".
@@ -338,7 +334,7 @@ func ConvertMapToQueryString(param map[string]interface{}) string //convert map
func ParseHttpResponse(resp *http.Response, obj interface{}) error //decode http response to specified interface func ParseHttpResponse(resp *http.Response, obj interface{}) error //decode http response to specified interface
``` ```
#### 8. random is for rand string and int generation ### 8. random is for rand string and int generation
- Generate random string and int. - Generate random string and int.
- Usage: import "github.com/duke-git/lancet/random". - Usage: import "github.com/duke-git/lancet/random".
@@ -367,7 +363,7 @@ func RandInt(min, max int) int //generate random int
func RandString(length int) string //generate random string func RandString(length int) string //generate random string
``` ```
#### 9. slice is for process slice ### 9. slice is for process slice
- Contain function for process slice. - Contain function for process slice.
- Usage: import "github.com/duke-git/lancet/slice" - Usage: import "github.com/duke-git/lancet/slice"
@@ -425,7 +421,7 @@ func GroupBy(slice, function interface{}) (interface{}, interface{}) // groups s
func Count(slice, function interface{}) int // Count iterates over elements of slice, returns a count of all matched elements func Count(slice, function interface{}) int // Count iterates over elements of slice, returns a count of all matched elements
``` ```
#### 10. strutil is for processing string ### 10. strutil is for processing string
- Contain functions to precess string - Contain functions to precess string
- Usage: import "github.com/duke-git/lancet/strutil" - Usage: import "github.com/duke-git/lancet/strutil"
@@ -467,7 +463,7 @@ func Wrap(str string, wrapWith string) string //wrap a string with another strin
func Unwrap(str string, wrapToken string) string //unwrap a given string from anther string. will change str value func Unwrap(str string, wrapToken string) string //unwrap a given string from anther string. will change str value
``` ```
#### 11. validator is for data validation ### 11. validator is for data validation
- Contain function for data validation. - Contain function for data validation.
- Usage: import "github.com/duke-git/lancet/validator". - Usage: import "github.com/duke-git/lancet/validator".

View File

@@ -1,4 +1,4 @@
<h1 style="width: 100%;">Lancet</h1> # Lancet
<p style="font-size: 18px"> <p style="font-size: 18px">
lancet柳叶刀是一个全面、高效、可复用的go语言工具函数库。 lancet受到了java apache common包和lodash.js的启发。 lancet柳叶刀是一个全面、高效、可复用的go语言工具函数库。 lancet受到了java apache common包和lodash.js的启发。
</p> </p>
@@ -15,29 +15,29 @@
简体中文 | [English](./README.md) 简体中文 | [English](./README.md)
### 特性 ## 特性
---
- 👏 全面、高效、可复用 - 👏 全面、高效、可复用
- 💪 140+常用go工具函数支持string、slice、datetime、net、crypt... - 💪 140+常用go工具函数支持string、slice、datetime、net、crypt...
- 💅 只依赖go标准库 - 💅 只依赖go标准库
- 🌍 所有导出函数单元测试覆盖率100% - 🌍 所有导出函数单元测试覆盖率100%
### 安装 ## 安装
---
```go ```go
go get github.com/duke-git/lancet go get github.com/duke-git/lancet
``` ```
### 用法 ## 用法
---
lancet是以包的结构组织代码的使用时需要导入相应的包名。例如如果使用字符串相关函数需要导入strutil包: lancet是以包的结构组织代码的使用时需要导入相应的包名。例如如果使用字符串相关函数需要导入strutil包:
```go ```go
import "github.com/duke-git/lancet/strutil" import "github.com/duke-git/lancet/strutil"
``` ```
### 例子 ## 例子
---
此处以字符串工具函数ReverseStr逆序字符串为例需要导入strutil包: 此处以字符串工具函数ReverseStr逆序字符串为例需要导入strutil包:
```go ```go
@@ -55,9 +55,8 @@ func main() {
} }
``` ```
### API文档 ## API文档
--- ### 1. convertor数据转换包
#### 1. convertor数据转换包
- 转换函数支持常用数据类型之间的转换 - 转换函数支持常用数据类型之间的转换
- 导入包import "github.com/duke-git/lancet/convertor" - 导入包import "github.com/duke-git/lancet/convertor"
@@ -95,7 +94,7 @@ func ToString(value interface{}) string //interface转成string
func StructToMap(value interface{}) (map[string]interface{}, error) //struct串转成map, 需要设置struct tag `json` func StructToMap(value interface{}) (map[string]interface{}, error) //struct串转成map, 需要设置struct tag `json`
``` ```
#### 2. cryptor加解密包 ### 2. cryptor加解密包
- 加密函数支持md5, hmac, aes, des, ras - 加密函数支持md5, hmac, aes, des, ras
- 导入包import "github.com/duke-git/lancet/cryptor" - 导入包import "github.com/duke-git/lancet/cryptor"
@@ -154,7 +153,7 @@ func RsaDecrypt(data []byte, privateKeyFileName string) []byte //RSA解密
``` ```
#### 3. datetime日期时间处理包 ### 3. datetime日期时间处理包
- 处理日期时间 - 处理日期时间
- 导入包import "github.com/duke-git/lancet/datetime" - 导入包import "github.com/duke-git/lancet/datetime"
@@ -189,7 +188,7 @@ func FormatTimeToStr(t time.Time, format string) string //时间格式化字符
func FormatStrToTime(str, format string) time.Time //字符串转换成时间 func FormatStrToTime(str, format string) time.Time //字符串转换成时间
``` ```
#### 4. fileutil文件处理包 ### 4. fileutil文件处理包
- 文件处理常用函数 - 文件处理常用函数
- 导入包import "github.com/duke-git/lancet/fileutil" - 导入包import "github.com/duke-git/lancet/fileutil"
@@ -226,7 +225,7 @@ func Zip(fpath string, destPath string) error //压缩文件fpath参数可以是
func UnZip(zipFile string, destPath string) error //解压文件并将文件存储在destPath目录中 func UnZip(zipFile string, destPath string) error //解压文件并将文件存储在destPath目录中
``` ```
#### 5. formatter格式化处理包 ### 5. formatter格式化处理包
- 格式化相关处理函数 - 格式化相关处理函数
- 导入包import "github.com/duke-git/lancet/formatter" - 导入包import "github.com/duke-git/lancet/formatter"
@@ -251,7 +250,7 @@ func main() {
func Comma(v interface{}, symbol string) string //用逗号每隔3位分割数字/字符串 func Comma(v interface{}, symbol string) string //用逗号每隔3位分割数字/字符串
``` ```
#### 6. function包可以控制函数执行支持部分函数式编程 ### 6. function包可以控制函数执行支持部分函数式编程
- 控制函数执行,支持部分函数式编程 - 控制函数执行,支持部分函数式编程
- 导入包import "github.com/duke-git/lancet/function" - 导入包import "github.com/duke-git/lancet/function"
@@ -287,7 +286,7 @@ func (w *Watcher) Reset() {} //重置代码watcher
func (w *Watcher) GetElapsedTime() time.Duration //get code excution elapsed time. func (w *Watcher) GetElapsedTime() time.Duration //get code excution elapsed time.
``` ```
#### 7. netutil网络处理包 ### 7. netutil网络处理包
- 处理ip, http请求相关函数 - 处理ip, http请求相关函数
- 导入包import "github.com/duke-git/lancet/netutil" - 导入包import "github.com/duke-git/lancet/netutil"
@@ -335,7 +334,7 @@ func ConvertMapToQueryString(param map[string]interface{}) string //将map转换
func ParseHttpResponse(resp *http.Response, obj interface{}) error //将http响应解码成特定interface func ParseHttpResponse(resp *http.Response, obj interface{}) error //将http响应解码成特定interface
``` ```
#### 8. random随机数处理包 ### 8. random随机数处理包
- 生成和处理随机数 - 生成和处理随机数
- 导入包import "github.com/duke-git/lancet/random" - 导入包import "github.com/duke-git/lancet/random"
@@ -364,7 +363,7 @@ func RandInt(min, max int) int //生成随机int
func RandString(length int) string //生成随机string func RandString(length int) string //生成随机string
``` ```
#### 9. slice切片操作包 ### 9. slice切片操作包
- 切片操作相关函数 - 切片操作相关函数
- 导入包import "github.com/duke-git/lancet/slice" - 导入包import "github.com/duke-git/lancet/slice"
@@ -422,7 +421,7 @@ func GroupBy(slice, function interface{}) (interface{}, interface{}) //根据函
func Count(slice, function interface{}) int func Count(slice, function interface{}) int
``` ```
#### 10. strutil字符串处理包 ### 10. strutil字符串处理包
- 字符串操作相关函数 - 字符串操作相关函数
- 导入包import "github.com/duke-git/lancet/strutil" - 导入包import "github.com/duke-git/lancet/strutil"
@@ -464,7 +463,7 @@ func Unwrap(str string, wrapToken string) string //解包裹字符串 Wrap("*abc
func SnakeCase(s string) string //字符串转为SnakeCase, "fooBar" -> "foo_bar" func SnakeCase(s string) string //字符串转为SnakeCase, "fooBar" -> "foo_bar"
``` ```
#### 11. validator验证器包 ### 11. validator验证器包
- 数据校验相关函数 - 数据校验相关函数
- 导入包import "github.com/duke-git/lancet/validator" - 导入包import "github.com/duke-git/lancet/validator"