-
Notifications
You must be signed in to change notification settings - Fork 0
/
func_util.go
361 lines (358 loc) · 7.73 KB
/
func_util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
package javascript
import (
"github.com/team-ide/go-tool/javascript/context_map"
"github.com/team-ide/go-tool/util"
)
func init() {
context_map.AddModule(&context_map.ModuleInfo{
Name: "util",
Comment: "工具模块",
FuncList: []*context_map.FuncInfo{
{
Name: "isEmpty",
Comment: "是否为nil或空字符串",
Func: util.IsEmpty,
},
{
Name: "isNotEmpty",
Comment: "是否不为nil或空字符串",
Func: util.IsNotEmpty,
},
{
Name: "isNull",
Comment: "是否为nil",
Func: util.IsNull,
},
{
Name: "isNotNull",
Comment: "是否不为nil或空字符串",
Func: util.IsNotNull,
},
{
Name: "isTrue",
Comment: "是否为真 判断是true、\"true\"、1、\"1\"",
Func: util.IsTrue,
},
{
Name: "isFalse",
Comment: "是否为否 判断不是true、\"true\"、1、\"1\"",
Func: util.IsFalse,
},
{
Name: "intIndexOf",
Comment: "返回 某个值 在数组中的索引位置,未找到返回 -1",
Func: util.IntIndexOf,
},
{
Name: "int64IndexOf",
Comment: "返回 某个值 在数组中的索引位置,未找到返回 -1",
Func: util.Int64IndexOf,
},
{
Name: "stringIndexOf",
Comment: "返回 某个值 在数组中的索引位置,未找到返回 -1",
Func: util.StringIndexOf,
},
{
Name: "arrayIndexOf",
Comment: "返回 某个值 在数组中的索引位置,未找到返回 -1",
Func: util.ArrayIndexOf,
},
{
Name: "setTempDir",
Comment: "设置临时目录",
Func: util.SetTempDir,
},
{
Name: "getTempDir",
Comment: "获取临时目录",
Func: util.GetTempDir,
},
{
Name: "newWaitGroup",
Comment: "创建 WaitGroup",
Func: util.NewWaitGroup,
},
{
Name: "newLocker",
Comment: "创建 Mutex Locker",
Func: util.NewLocker,
},
{
Name: "getRootDir",
Comment: "获取当前程序根路径",
Func: util.GetRootDir,
},
{
Name: "formatPath",
Comment: "格式化路径",
Func: util.FormatPath,
},
{
Name: "getAbsolutePath",
Comment: "获取路径觉得路径",
Func: util.GetAbsolutePath,
},
{
Name: "pathExists",
Comment: "路径文件是否存在",
Func: util.PathExists,
},
{
Name: "loadDirFiles",
Comment: "加载目录下文件 读取文件内容(key为文件名为相对路径)",
Func: util.LoadDirFiles,
},
{
Name: "loadDirFilenames",
Comment: "加载目录下文件(文件名为相对路径)",
Func: util.LoadDirFilenames,
},
{
Name: "readFile",
Comment: "读取文件内容 返回 []byte",
Func: util.ReadFile,
},
{
Name: "readFileString",
Comment: "读取文件内容 返回字符串",
Func: util.ReadFileString,
},
{
Name: "writeFile",
Comment: "写入文件内容",
Func: util.WriteFile,
},
{
Name: "writeFileString",
Comment: "写入文件内容",
Func: util.WriteFileString,
},
{
Name: "readLine",
Comment: "逐行读取文件",
Func: util.ReadLine,
},
{
Name: "getFileType",
Comment: "用文件前面几个字节来判断",
Func: util.GetFileType,
},
{
Name: "getIpFromAddr",
Comment: "获取当前IP",
Func: util.GetIpFromAddr,
},
{
Name: "getLocalIPList",
Comment: "获取当前IP列表",
Func: util.GetLocalIPList,
},
{
Name: "objToJson",
Comment: "对象 转 json 字符串",
Func: util.ObjToJson,
},
{
Name: "jsonToMap",
Comment: "json 字符串 转 map对象",
Func: util.JsonToMap,
},
{
Name: "jsonToObj",
Comment: "json 字符串 转 对象",
Func: util.JsonToObj,
},
{
Name: "getLock",
Comment: "获取一个Locker,如果不存在,则新建",
Func: util.GetLock,
},
{
Name: "lockByKey",
Comment: "根据Key进行同步锁",
Func: util.LockByKey,
},
{
Name: "unlockByKey",
Comment: "根据Key进行解锁同步锁",
Func: util.UnlockByKey,
},
{
Name: "getLogger",
Comment: "获取logger输出对象",
Func: util.GetLogger,
},
{
Name: "getMD5",
Comment: "获取MD5字符串",
Func: util.GetMD5,
},
{
Name: "randomInt",
Comment: "获取随机数",
Func: util.RandomInt,
},
{
Name: "randomInt64",
Comment: "获取随机数",
Func: util.RandomInt64,
},
{
Name: "stringToInt",
Comment: "字符串转 int",
Func: util.StringToInt,
},
{
Name: "stringToInt64",
Comment: "字符串转 int64",
Func: util.StringToInt64,
},
{
Name: "stringToFloat64",
Comment: "字符串转 float64",
Func: util.StringToFloat64,
},
{
Name: "rsaEncryptByKey",
Comment: "RSA加密",
Func: util.RsaEncryptByKey,
},
{
Name: "rsaDecryptByKey",
Comment: "RSA解密",
Func: util.RsaDecryptByKey,
},
{
Name: "rsaEncrypt",
Comment: "加密",
Func: util.RsaEncrypt,
},
{
Name: "rsaDecrypt",
Comment: "解密",
Func: util.RsaDecrypt,
},
{
Name: "firstToUpper",
Comment: "字符首字母大写",
Func: util.FirstToUpper,
},
{
Name: "firstToLower",
Comment: "字符首字母小写",
Func: util.FirstToLower,
},
{
Name: "marshal",
Comment: "转换为大驼峰命名法则 首字母大写,“_” 忽略后大写",
Func: util.Marshal,
},
{
Name: "getStringValue",
Comment: "将传入的值转为字符串",
Func: util.GetStringValue,
},
{
Name: "toPinYin",
Comment: "将姓名转为拼音",
Func: util.ToPinYin,
},
{
Name: "randomString",
Comment: "获取随机字符串",
Func: util.RandomString,
},
{
Name: "randomUserName",
Comment: "随机姓名",
Func: util.RandomUserName,
},
{
Name: "strPadLeft",
Comment: "在字符串 左侧补全 字符串 到 指定长度",
Func: util.StrPadLeft,
},
{
Name: "strPadRight",
Comment: "在字符串 右侧补全 字符串 到 指定长度",
Func: util.StrPadRight,
},
{
Name: "getNow",
Comment: "获取当前时间",
Func: util.GetNow,
},
{
Name: "getNowNano",
Comment: "获取当前时间戳 到纳秒",
Func: util.GetNowNano,
},
{
Name: "getNowMilli",
Comment: "获取当前时间戳 到毫秒",
Func: util.GetNowMilli,
},
{
Name: "getNowSecond",
Comment: "获取当前时间戳 到秒",
Func: util.GetNowSecond,
},
{
Name: "getNanoByTime",
Comment: "获取时间戳 到纳秒",
Func: util.GetNanoByTime,
},
{
Name: "getMilliByTime",
Comment: "获取时间戳 到毫秒",
Func: util.GetMilliByTime,
},
{
Name: "getSecondByTime",
Comment: "获取时间戳 到秒",
Func: util.GetSecondByTime,
},
{
Name: "getNowFormat",
Comment: "获取当前格式化时间 `2006-01-02 15:04:05`",
Func: util.GetNowFormat,
},
{
Name: "getFormatByTime",
Comment: "获取格式化时间 `2006-01-02 15:04:05`",
Func: util.GetFormatByTime,
},
{
Name: "timeFormat",
Comment: "时间格式化 默认 `2006-01-02 15:04:05`",
Func: util.TimeFormat,
},
{
Name: "getUUID",
Comment: "生成UUID",
Func: util.GetUUID,
},
{
Name: "gzipBytes",
Comment: "压缩",
Func: util.GzipBytes,
},
{
Name: "unGzipBytes",
Comment: "解压",
Func: util.UnGzipBytes,
},
{
Name: "zip",
Comment: "zip压缩 srcFile 文件路径,destZip压缩包保存路径",
Func: util.Zip,
},
{
Name: "unZip",
Comment: "zip解压 zipFile 压缩包地址 destDir 解压保存文件夹",
Func: util.UnZip,
},
},
})
}