-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
142 lines (119 loc) · 4.38 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
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
package main
import (
"bufio"
"embed"
"fmt"
"log"
"os"
"regexp"
"sort"
"strings"
)
var Lines []string
var Lines2 []string
var Lines3 []string
var TempSlice []string
//go:embed mimetype.txt
var local embed.FS
func main() {
file, err := os.Open("input.txt")
if err != nil {
log.Fatal(err)
}
defer file.Close()
TempSlice = embedread("mimetype.txt")
mimetypeLines := make(map[string]bool)
for _, v1 := range TempSlice {
mimetypeLines[v1] = true
}
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
if !strings.HasPrefix(line, "http://") && !strings.HasPrefix(line, "https://") && !strings.HasPrefix(line, "dict://") && !strings.HasPrefix(line, "jar://") && !strings.HasPrefix(line, "ldap://") && !strings.HasPrefix(line, "netdoc://") && !strings.HasPrefix(line, "ftp://") && !strings.HasPrefix(line, "sftp://") && !strings.HasPrefix(line, "tftp://") {
if !mimetypeLines[line] {
match1, _ := regexp.MatchString(`(?i)(.*\.(md|woff|3g2|3gp|7z|aac|abw|aif|aifc|aiff|arc|au|avi|azw|bin|bmp|bz|bz2|cmx|cod|csh|css|csv|doc|docx|eot|epub|gif|gz|ico|ics|ief|jar|jfif|jpe|jpeg|jpg|m3u|mid|midi|mjs|mp2|mp3|mpa|mpe|mpeg|mpg|mpkg|mpp|mpv2|odp|ods|odt|oga|ogv|ogx|otf|pbm|pdf|pgm|png|pnm|ppm|ppt|pptx|ra|ram|rar|ras|rgb|rmi|rtf|snd|svg|swf|tar|tif|tiff|ttf|vsd|wav|weba|webm|webp|woff2|woff|xbm|xls|xlsx|xpm|xul|xwd|zip|zip|exe|mp4|flv|less)\?.*)|(.*\.(md|woff|3g2|3gp|7z|aac|abw|aif|aifc|aiff|arc|au|avi|azw|bin|bmp|bz|bz2|cmx|cod|csh|css|csv|doc|docx|eot|epub|gif|gz|ico|ics|ief|jar|jfif|jpe|jpeg|jpg|m3u|mid|midi|mjs|mp2|mp3|mpa|mpe|mpeg|mpg|mpkg|mpp|mpv2|odp|ods|odt|oga|ogv|ogx|otf|pbm|pdf|pgm|png|pnm|ppm|ppt|pptx|ra|ram|rar|ras|rgb|rmi|rtf|snd|svg|swf|tar|tif|tiff|ttf|vsd|wav|weba|webm|webp|woff2|woff|xbm|xls|xlsx|xpm|xul|xwd|zip|zip|exe|mp4|flv|less))`, line)
if match1 {
//fmt.Println("------------------------------------------rule3-1", line)
} else {
match2, _ := regexp.MatchString(`(\.(?i)(woff|3g2|3gp|7z|aac|abw|aif|aifc|aiff|arc|au|avi|azw|bin|bmp|bz|bz2|cmx|cod|csh|css|csv|doc|docx|eot|epub|gif|gz|ico|ics|ief|jar|jfif|jpe|jpeg|jpg|m3u|mid|midi|mjs|mp2|mp3|mpa|mpe|mpeg|mpg|mpkg|mpp|mpv2|odp|ods|odt|oga|ogv|ogx|otf|pbm|pdf|pgm|png|pnm|ppm|ppt|pptx|ra|ram|rar|ras|rgb|rmi|rtf|snd|svg|swf|tar|tif|tiff|ttf|vsd|wav|weba|webm|webp|woff2|woff|xbm|xls|xlsx|xpm|xul|xwd|zip|zip|exe|mp4|flv|less)(\.\%.*$|\;|\?|\~|\-))`, line)
if match2 {
//fmt.Println("------------------------------------------rule3-2", line)
} else {
match3, _ := regexp.MatchString(`(\.js$)|(\.js\.\%.*$)|(\.js\;)|(\.js\?)|(\.js\.map$)|(\.css\.map$)|(\.min\.map$)`, line)
if match3 {
//fmt.Println("------------------------------------------rule3-3", line)
} else {
if line == "" {
continue
} else {
if strings.HasPrefix(line, "//") {
Lines3 = append(Lines3, line)
} else {
if !strings.HasPrefix(line, "/") {
line = "/" + line
Lines = append(Lines, line)
} else {
Lines = append(Lines, line)
}
}
}
}
}
}
} else {
//fmt.Println("------------------------------------------rule2", line)
}
} else {
//fmt.Println("------------------------------------------rule1", line)
Lines2 = append(Lines2, line)
}
}
//rule4
sort.Strings(Lines)
Lines = removeDuplicates(Lines)
TodoTxt("output.txt", Lines)
TodoTxt("output2.txt", Lines2)
TodoTxt("output3.txt", Lines3)
}
func removeDuplicates(slice []string) []string {
seen := make(map[string]bool)
result := []string{}
for _, item := range slice {
if !seen[item] {
seen[item] = true
result = append(result, item)
}
}
return result
}
func TodoTxt(filename string, dic []string) {
filePath := filename
file, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
fmt.Println("文件打开失败", err)
}
defer file.Close()
write := bufio.NewWriter(file)
for _, v := range dic {
write.WriteString(v + "\n")
}
write.Flush()
fmt.Println("txt 格式文件已输出到: ", filePath)
}
func embedread(filePath string) []string {
var resp5 []string
f, err := local.Open(filePath)
if err != nil {
log.Fatal(err)
}
defer f.Close()
scanner := bufio.NewScanner(f)
for scanner.Scan() {
// do something with a line
resp5 = append(resp5, scanner.Text())
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
return resp5
}