From 9426da7d6b629904fee7b7707be834cede859323 Mon Sep 17 00:00:00 2001 From: what-00 Date: Thu, 13 Apr 2023 11:06:42 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=20=E6=96=B0=E5=A2=9E=20GetAbsPath=20?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- support/util.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/support/util.go b/support/util.go index 37e97c0..7480f38 100644 --- a/support/util.go +++ b/support/util.go @@ -2,6 +2,8 @@ package support import ( "fmt" + "os" + "path/filepath" "reflect" "strings" "unsafe" @@ -161,3 +163,13 @@ func UcFirst(s string) string { func StudlyCase(s string) string { return strings.Replace(strings.Title(strings.Replace(s, "-", " ", -1)), " ", "", -1) } + +func GetAbsPath(s string) string { + if strings.HasPrefix(s, "/") { + return s + } else if dir, err := os.Getwd(); err == nil { + return filepath.Join(dir, s) + } + + return s +}