Skip to content

Commit b86ae3a

Browse files
committed
代码样式改进
1 parent 3ba8c45 commit b86ae3a

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

plugin/wordcount/main.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var (
2626
seg gse.Segmenter
2727
)
2828

29+
// 保存聊天消息的时间与内容到json
2930
type MessageRecord struct {
3031
Time int64 `json:"time"`
3132
Text string `json:"text"`
@@ -37,12 +38,18 @@ func appendJSONLine(filePath string, record MessageRecord) {
3738
return
3839
}
3940
defer f.Close()
41+
4042
data, err := json.Marshal(record)
4143
if err != nil {
4244
return
4345
}
44-
f.Write(data)
45-
f.WriteString("\n")
46+
// 错误处理
47+
if _, err := f.Write(data); err != nil {
48+
return
49+
}
50+
if _, err := f.WriteString("\n"); err != nil {
51+
return
52+
}
4653
}
4754

4855
func loadStopwords() {

0 commit comments

Comments
 (0)