We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3ba8c45 commit b86ae3aCopy full SHA for b86ae3a
1 file changed
plugin/wordcount/main.go
@@ -26,6 +26,7 @@ var (
26
seg gse.Segmenter
27
)
28
29
+// 保存聊天消息的时间与内容到json
30
type MessageRecord struct {
31
Time int64 `json:"time"`
32
Text string `json:"text"`
@@ -37,12 +38,18 @@ func appendJSONLine(filePath string, record MessageRecord) {
37
38
return
39
}
40
defer f.Close()
41
+
42
data, err := json.Marshal(record)
43
if err != nil {
44
45
- f.Write(data)
- f.WriteString("\n")
46
+ // 错误处理
47
+ if _, err := f.Write(data); err != nil {
48
+ return
49
+ }
50
+ if _, err := f.WriteString("\n"); err != nil {
51
52
53
54
55
func loadStopwords() {
0 commit comments