Skip to content

Commit 1a19679

Browse files
committed
update 2023年 9月11日 星期一 17时48分52秒 CST
1 parent 9aea74a commit 1a19679

2 files changed

Lines changed: 31 additions & 10 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
push.sh
22
.idea
33
dist/
4+
main

main.go

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"bufio"
5+
"embed"
56
"fmt"
67
"log"
78
"os"
@@ -13,6 +14,10 @@ import (
1314
var Lines []string
1415
var Lines2 []string
1516
var Lines3 []string
17+
var TempSlice []string
18+
19+
//go:embed mimetype.txt
20+
var local embed.FS
1621

1722
func main() {
1823

@@ -22,17 +27,10 @@ func main() {
2227
}
2328
defer file.Close()
2429

25-
mimetypeFile, err := os.Open("mimetype.txt")
26-
if err != nil {
27-
log.Fatal(err)
28-
}
29-
defer mimetypeFile.Close()
30-
31-
mimetypeScanner := bufio.NewScanner(mimetypeFile)
30+
TempSlice = embedread("mimetype.txt")
3231
mimetypeLines := make(map[string]bool)
33-
for mimetypeScanner.Scan() {
34-
line := mimetypeScanner.Text()
35-
mimetypeLines[line] = true
32+
for _, v1 := range TempSlice {
33+
mimetypeLines[v1] = true
3634
}
3735

3836
scanner := bufio.NewScanner(file)
@@ -120,3 +118,25 @@ func TodoTxt(filename string, dic []string) {
120118
fmt.Println("txt 格式文件已输出到: ", filePath)
121119

122120
}
121+
122+
func embedread(filePath string) []string {
123+
var resp5 []string
124+
125+
f, err := local.Open(filePath)
126+
if err != nil {
127+
log.Fatal(err)
128+
}
129+
defer f.Close()
130+
scanner := bufio.NewScanner(f)
131+
for scanner.Scan() {
132+
// do something with a line
133+
resp5 = append(resp5, scanner.Text())
134+
}
135+
136+
if err := scanner.Err(); err != nil {
137+
log.Fatal(err)
138+
}
139+
140+
return resp5
141+
142+
}

0 commit comments

Comments
 (0)