From 898257b25b7c4dd18cd72d40a37c818b55665c8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AE=87=E7=BF=94?= <178529795@qq.com> Date: Wed, 4 Mar 2020 11:43:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=87=BD=E6=95=B0CurrentDir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- util/util.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/util/util.go b/util/util.go index e439e04..7ac63d6 100644 --- a/util/util.go +++ b/util/util.go @@ -4,6 +4,8 @@ import ( "bufio" "io" "os" + "path/filepath" + "runtime" ) // 检查文件或目录是否存在 @@ -38,3 +40,11 @@ func ReadFileLines(filename string) (lines []string, err error) { return } + +func CurrentDir(path ...string) string { + _, currentFilePath, _, _ := runtime.Caller(1) + if len(path) == 0 { + return filepath.Dir(currentFilePath) + } + return filepath.Join(filepath.Dir(currentFilePath), filepath.Join(path...)) +}