mirror of
				https://github.com/mickael-kerjean/filestash.git
				synced 2025-11-04 05:27:04 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			47 lines
		
	
	
		
			741 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			741 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package common
 | 
						|
 | 
						|
import (
 | 
						|
	"os"
 | 
						|
	"path/filepath"
 | 
						|
	"strings"
 | 
						|
)
 | 
						|
 | 
						|
func GetCurrentDir() string {
 | 
						|
	ex, _ := os.Executable()
 | 
						|
	return filepath.Dir(ex)
 | 
						|
}
 | 
						|
 | 
						|
func GetAbsolutePath(p string) string {
 | 
						|
	return filepath.Join(GetCurrentDir(), p)
 | 
						|
}
 | 
						|
 | 
						|
func IsDirectory(path string) bool {
 | 
						|
	if path == "" {
 | 
						|
		return false
 | 
						|
	}
 | 
						|
	if path[len(path) - 1:] != "/" {
 | 
						|
		return false
 | 
						|
	}
 | 
						|
	return true
 | 
						|
}
 | 
						|
 | 
						|
/*
 | 
						|
 * Join 2 path together, result has a file
 | 
						|
 */
 | 
						|
func JoinPath(base, file string) string {
 | 
						|
	filePath := filepath.Join(base, file)
 | 
						|
	if strings.HasPrefix(filePath, base) == false {
 | 
						|
		return base
 | 
						|
	}
 | 
						|
	return filePath
 | 
						|
}
 | 
						|
 | 
						|
func EnforceDirectory(path string) string {
 | 
						|
	if path == "" {
 | 
						|
		return "/"
 | 
						|
	} else if path[len(path) - 1:] == "/" {
 | 
						|
		return path
 | 
						|
	}
 | 
						|
	return path + "/"
 | 
						|
}
 |