From 178b55ad52fc8b112e2b9cd170532c0a0d870c58 Mon Sep 17 00:00:00 2001 From: fumiama Date: Fri, 6 Aug 2021 18:52:41 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A9=F0=9F=91=8C=20make=20lint=20happy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin_diana/data/text.go | 4 ++++ plugin_diana/tools/convert.go | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/plugin_diana/data/text.go b/plugin_diana/data/text.go index 91a808ab..9bceff13 100644 --- a/plugin_diana/data/text.go +++ b/plugin_diana/data/text.go @@ -1,3 +1,4 @@ +// Package data 加载位于 datapath 的小作文 package data import ( @@ -13,6 +14,7 @@ const ( var ( compo Composition + // 小作文数组 Array []string ) @@ -29,6 +31,7 @@ func init() { }() } +// 加载小作文 func LoadText() error { if _, err := os.Stat(pbfile); err == nil || os.IsExist(err) { f, err := os.Open(pbfile) @@ -46,6 +49,7 @@ func LoadText() error { return nil } +// 添加小作文 func AddText(txt string) error { if txt != "" { compo.Array = append(compo.Array, txt) diff --git a/plugin_diana/tools/convert.go b/plugin_diana/tools/convert.go index a462a818..41ff1323 100644 --- a/plugin_diana/tools/convert.go +++ b/plugin_diana/tools/convert.go @@ -3,6 +3,7 @@ package main import ( "bufio" + "fmt" "os" "github.com/FloatTech/ZeroBot-Plugin/plugin_diana/data" @@ -27,7 +28,7 @@ func main() { scanner := bufio.NewScanner(file) // optionally, resize scanner's capacity for lines over 64K, see next example for scanner.Scan() { - //fmt.Println(scanner.Text()) + // fmt.Println(scanner.Text()) compo.Array = append(compo.Array, scanner.Text()) } @@ -39,6 +40,13 @@ func main() { f, err1 := os.OpenFile(os.Args[2], os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644) if err1 == nil { defer f.Close() - f.Write(data) + _, err2 := f.Write(data) + if err2 == nil { + fmt.Println("成功") + } else { + panic(err2) + } + } else { + panic(err1) } }