-
Notifications
You must be signed in to change notification settings - Fork 20
/
main.go
44 lines (39 loc) · 1.05 KB
/
main.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
package main
import (
"auditlimit/api"
"auditlimit/config"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/text/gstr"
)
func main() {
s := g.Server()
s.SetPort(config.PORT)
s.BindHandler("/", Index)
s.BindHandler("/audit_limit", api.AuditLimit)
s.Run()
}
func Index(r *ghttp.Request) {
r.Response.Write("Hello Xyhelper,this is auditlimit")
}
func init() {
// 判断 ./data/keywords.txt 文件是否存在
if gfile.Exists("./data/keywords.txt") {
// 读取 ./data/keywords.txt 文件内容
keyWords := gfile.GetContents("./data/keywords.txt")
// 将文件内容按照换行符分割为切片
keyWordsSlice := gstr.Split(keyWords, "\n")
// 去除切片中的空格及空行
if len(keyWordsSlice) > 0 {
for i := 0; i < len(keyWordsSlice); i++ {
keyWordsSlice[i] = gstr.Trim(keyWordsSlice[i])
if keyWordsSlice[i] == "" {
keyWordsSlice = append(keyWordsSlice[:i], keyWordsSlice[i+1:]...)
i--
}
}
}
config.ForbiddenWords = keyWordsSlice
}
}