Skip to content

Commit e2e97c8

Browse files
committed
refactor(root): 修改 Readme描述
1 parent d1a335e commit e2e97c8

File tree

1 file changed

+153
-12
lines changed

1 file changed

+153
-12
lines changed

Diff for: README.md

+153-12
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,162 @@
1-
go工具包 ⚗️
2-
---
1+
<h1 align=center>go工具包 ⚗️</h1>
32

3+
<p align=center>这是一个Go语言工具包,旨在提供缓存、定时器和切片工具,为开发者提供方便和高效的工具,支持Go1.18的范型特性。</p>
44

5-
安装 ⚒️
6-
---
5+
<p align=center>Made with ♥ by <a href="https://lomtom.cn">lomtom</a></p>
6+
7+
<p align=center>如果你觉得这个项目有用,请给它一个⭐以表示你的支持</p>
8+
9+
## 特性 💡
10+
11+
1. **[Map缓存](cache/README.md)**: 提供了一个基于Go语言`map`的缓存工具,允许开发者轻松存储和检索键值对数据,加速数据访问。
12+
13+
2. **[定时器](job/README.md)**: 内置的定时器工具允许您创建定时任务,以便在指定的时间间隔内执行特定的操作,适用于需要定时执行代码的场景。
14+
15+
3. **[Slice工具](slice/README.md)**: 提供了一组操作切片的工具函数,使得在处理切片数据时更加便捷和高效。
16+
17+
## 安装 ⚒️
18+
19+
使用Go模块的方式,您可以轻松地将该工具包集成到您的项目中:
720
```shell
8-
go get github.com/lomtom/go-utils/v2
21+
go get github.com/lomtom/go-utils
922
```
1023

11-
使用
12-
---
13-
1. [提供map缓存](cache/README.md)
14-
2. [提供定时器](job/README.md)
15-
3. [slice工具](slice/README.md)
24+
## 使用
25+
26+
以下是工具的简单使用,更多使用请点击标题查看详细介绍。
27+
28+
### 1. [Map缓存](cache/README.md)
29+
30+
使用Map缓存工具,您可以轻松存储和检索键值对数据,加速数据访问。
31+
```go
32+
package main
33+
34+
import (
35+
"fmt"
36+
"github.com/lomtom/go-utils/cache"
37+
)
38+
39+
40+
func main(){
41+
c,err := cache.NewMapCache[int]()
42+
if err != nil {
43+
fmt.Println("err:", err)
44+
return
45+
}
46+
c.Set("1", 1)
47+
fmt.Println(c.Get("1"))
48+
}
49+
```
50+
51+
### 2. **[定时器](job/README.md)**
52+
53+
使用定时器工具,您可以创建定时任务,以便在指定的时间间隔内执行特定的操作。
54+
```go
55+
package main
1656

57+
import (
58+
"fmt"
59+
"github.com/lomtom/go-utils/job"
60+
)
1761

18-
注意 ⚠️
62+
63+
func main(){
64+
j := job.NewTimerJob(func(j job.TimerJob) {
65+
fmt.Println("这是一个定时任务")
66+
},
67+
// 设置间隔时间(默认一分钟)
68+
job.SetDuration(time.Second))
69+
err := j.Start()
70+
if err != nil {
71+
log.Println(err)
72+
return
73+
}
74+
time.Sleep(time.Second * 4)
75+
}
76+
```
77+
78+
```go
79+
2022/02/24 16:44:30 job_1645692270490900 第1次 开始执行任务
80+
2022/02/24 16:44:31 job_1645692270490900 第1次 执行时任务 start....
81+
这是一个定时任务
82+
2022/02/24 16:44:31 job_1645692270490900 第1次 执行时任务 end....
83+
2022/02/24 16:44:32 job_1645692270490900 第2次 执行时任务 start....
84+
这是一个定时任务
85+
2022/02/24 16:44:32 job_1645692270490900 第2次 执行时任务 end....
86+
2022/02/24 16:44:33 job_1645692270490900 第3次 执行时任务 start....
87+
这是一个定时任务
88+
2022/02/24 16:44:33 job_1645692270490900 第3次 执行时任务 end....
89+
2022/02/24 16:44:34 job_1645692270490900 第4次 执行时任务 start....
90+
这是一个定时任务
91+
2022/02/24 16:44:34 job_1645692270490900 第4次 执行时任务 end....
92+
```
93+
94+
### 3. **[Slice工具](slice/README.md)**
95+
96+
提供了一组操作切片的工具函数,使得在处理切片数据时更加便捷和高效。
97+
98+
```go
99+
type people struct {
100+
name string
101+
age int
102+
}
103+
104+
func TestSize(t *testing.T) {
105+
a := assert.NewAssert(t)
106+
a.Equal(0, Size([]int{}))
107+
a.Equal(3, Size([]int{1, 2, 3}))
108+
}
109+
110+
func TestIsEmpty(t *testing.T) {
111+
a := assert.NewAssert(t)
112+
a.Equal(true, IsEmpty([]int{}))
113+
a.Equal(false, IsEmpty([]int{1, 2, 3}))
114+
}
115+
116+
func TestContains(t *testing.T) {
117+
a := assert.NewAssert(t)
118+
a.Equal(true, Contains([]int{1, 2, 3}, 1))
119+
a.Equal(true, Contains([]people{}, people{name: "lomtom"}))
120+
}
121+
122+
func TestContainsAll(t *testing.T) {
123+
a := assert.NewAssert(t)
124+
a.Equal(true, ContainsAll([]int{1, 2, 3}))
125+
a.Equal(true, ContainsAll([]int{1, 2, 3}, 1, 2, 3))
126+
a.Equal(false, ContainsAll([]int{1, 2, 3}, 1, 2, 3, 4))
127+
a.Equal(true, ContainsAll([]people{{name: "lomtom"}}, people{name: "lomtom"}))
128+
}
129+
130+
func TestAddAll(t *testing.T) {
131+
a := assert.NewAssert(t)
132+
a.Equal([]int{1, 2, 3, 1, 2, 3}, AddAll([]int{1, 2, 3}, []int{1, 2, 3}...))
133+
a.Equal([]people{{name: "lomtom"}, {name: "lomtom"}}, AddAll([]people{{name: "lomtom"}}, people{name: "lomtom"}))
134+
}
135+
136+
func TestReplaceAll(t *testing.T) {
137+
a := assert.NewAssert(t)
138+
a.Equal([]int{4, 4, 3, 1, 4, 3}, ReplaceAll([]int{1, 2, 3, 1, 2, 3}, func(value int) int {
139+
if value == 2 {
140+
return 4
141+
}
142+
return value
143+
}))
144+
}
145+
146+
func TestRemoveAll(t *testing.T) {
147+
a := assert.NewAssert(t)
148+
a.Equal([]int{4}, RemoveAll([]int{1, 2, 3, 4}, []int{1, 2, 3}...))
149+
a.Equal([]people{}, RemoveAll([]people{{name: "lomtom"}}, people{name: "lomtom"}))
150+
}
151+
```
152+
153+
注意 ⚠️
19154
---
20155
1. 由于v2使用Go 1.18 开发的工具包,低版本将不兼容
21-
2. 如果是低版本请查看[master](https://github.com/lomtom/go-utils/tree/master)
156+
2. 如果是低版本请查看[v0.1.4](https://github.com/lomtom/go-utils/tree/v0.1.4)
157+
158+
## 贡献
159+
欢迎贡献代码、报告问题或提出建议。请通过GitHub Issues和Pull Requests参与贡献。
160+
161+
## 许可证
162+
该工具包基于 [MIT许可证](LICENSE) 发布。

0 commit comments

Comments
 (0)