| 
									
										
										
										
											2022-03-17 09:52:22 +00:00
										 |  |  | 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 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-03-17 10:15:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // GetGlobalConfigurationFile returns OS specific file location
 | 
					
						
							|  |  |  | func GetGlobalConfigurationFile(appname string, file string) string { | 
					
						
							|  |  |  | 	return filepath.Join(GetGlobalConfigurationDirectory(appname), file) | 
					
						
							|  |  |  | } |