File tree Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Original file line number Diff line number Diff line change 11package utils
22
33import (
4+ "errors"
45 "fmt"
56 "io/ioutil"
67 "log"
@@ -291,7 +292,6 @@ func ParentDirectory(dirctory string) string {
291292 * @date 2019/6/28 15:53
292293 */
293294func CurrentDirectory () string {
294- // sep := string(os.PathSeparator)
295295 return strings .Replace (OsPath (), "\\ " , "/" , - 1 )
296296}
297297
@@ -301,11 +301,34 @@ func CurrentDirectory() string {
301301 * @author claer woytu.com
302302 * @date 2019/6/29 3:22
303303 */
304- func ContextPath (root string ) string {
304+ func ContextPath (root string ) ( path string , err error ) {
305305 // 获取当前绝对路径
306306 dir , err := os .Getwd ()
307307 if err != nil {
308308 log .Fatal (err )
309309 }
310- return Substring (dir , 0 , strings .LastIndex (dir , root )+ len (root ))
310+ index := strings .LastIndex (dir , root )
311+ if len (dir ) < len (root ) || index <= 0 {
312+ err = errors .New ("错误:路径不正确" )
313+ return dir , err
314+ }
315+ return dir [0 : strings .LastIndex (dir , root )+ len (root )], nil
316+ }
317+
318+ /**
319+ * 路径标准化拼接
320+ *
321+ * @param paths 可变路径参数
322+ * @return
323+ * @author claer woytu.com
324+ * @date 2019/6/29 3:46
325+ */
326+ func PathStitching (paths ... string ) string {
327+ sep := string (os .PathSeparator )
328+ path := ""
329+ for _ , value := range paths {
330+ fmt .Println (path )
331+ path = path + sep + value
332+ }
333+ return path [1 :]
311334}
You can’t perform that action at this time.
0 commit comments