From fa15f852fda638aa72e172f5aae7dac999692900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=8C=E6=B5=B7=E4=BB=B2=E5=AD=90?= Date: Fri, 3 Sep 2021 22:28:17 +0800 Subject: [PATCH] =?UTF-8?q?snippet=E6=94=BE=E4=BA=8E=E6=A0=B9=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- snippet/main.go => main.go | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) rename snippet/main.go => main.go (95%) diff --git a/README.md b/README.md index f8db93f..381a7e2 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ #### 组件工具 1. 安装 -> go install myschools.me/suguo/snippet/snippet@latest +> go install myschools.me/suguo/snippet@latest 2. 使用 > snippet -dl mysql diff --git a/snippet/main.go b/main.go similarity index 95% rename from snippet/main.go rename to main.go index 7e52b60..0dc9989 100644 --- a/snippet/main.go +++ b/main.go @@ -42,7 +42,8 @@ func main() { // get all file link and download it func dl(client http.Client, path string, wg *sync.WaitGroup) { - if !isExist(path) { + _, err := os.Stat(path) + if !os.IsNotExist(err) { os.MkdirAll(path, 0775) } @@ -112,9 +113,3 @@ func getHtml(client http.Client, url string) ([]byte, error) { } return data, nil } - -// if file or directory exits -func isExist(path string) bool { - _, err := os.Stat(path) - return !os.IsNotExist(err) -}