53 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Go
		
	
	
	
			
		
		
	
	
			53 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Go
		
	
	
	
| package util
 | |
| 
 | |
| import (
 | |
| 	"os"
 | |
| 	"path/filepath"
 | |
| 	"strings"
 | |
| )
 | |
| 
 | |
| // FileExists Checks if a file with the given file name exists
 | |
| func FileExists(fileName string) bool {
 | |
| 	if _, err := os.Stat(fileName); os.IsNotExist(err) {
 | |
| 		return false
 | |
| 	}
 | |
| 	return true
 | |
| }
 | |
| 
 | |
| // JoiningSlash joining http path elements
 | |
| func JoiningSlash(elem ...string) string {
 | |
| 	return joiningSlash(elem)
 | |
| }
 | |
| 
 | |
| func joiningSlash(elem []string) string {
 | |
| 	path := ""
 | |
| 	for _, e := range elem {
 | |
| 		if e != "" {
 | |
| 			if path == "" {
 | |
| 				path = e
 | |
| 			} else {
 | |
| 				path = singleJoiningSlash(path, e)
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| 	return path
 | |
| }
 | |
| 
 | |
| func singleJoiningSlash(a, b string) string {
 | |
| 	filepath.Join(a, b)
 | |
| 	aslash := strings.HasSuffix(a, "/")
 | |
| 	bslash := strings.HasPrefix(b, "/")
 | |
| 	switch {
 | |
| 	case aslash && bslash:
 | |
| 		return a + b[1:]
 | |
| 	case !aslash && !bslash:
 | |
| 		return a + "/" + b
 | |
| 	}
 | |
| 	return a + b
 | |
| }
 | |
| 
 | |
| // GetGlobalConfigurationFile returns OS specific file location
 | |
| func GetGlobalConfigurationFile(appname string, file string) string {
 | |
| 	return filepath.Join(GetGlobalConfigurationDirectory(appname), file)
 | |
| }
 |