github.com/qxnw/lib4go@v0.0.0-20180426074627-c80c7e84b925/osext/osext.go (about) 1 // Copyright 2012 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Extensions to the standard "os" package. 6 package osext 7 8 import ( 9 "path" 10 "path/filepath" 11 ) 12 13 // Executable returns an absolute path that can be used to 14 // re-invoke the current program. 15 // It may not be valid after the current program exits. 16 func Executable() (string, error) { 17 p, err := executable() 18 return filepath.Clean(p), err 19 } 20 21 // Returns same path as Executable, returns just the folder 22 // path. Excludes the executable name and any trailing slash. 23 func ExecutableFolder() (string, error) { 24 p, err := Executable() 25 if err != nil { 26 return "", err 27 } 28 29 return filepath.Dir(p), nil 30 } 31 32 //GetAbsPath 获取绝对路径 33 func GetAbsPath(filename string) (string, error) { 34 if !path.IsAbs(filename) { 35 filename, err := filepath.Abs(filename) 36 return filename, err 37 } 38 return filename, nil 39 }