Support utils.FileExists/1
Support predicate for checking if a file exists on disk.
This commit is contained in:
		
							parent
							
								
									3ae3b6f039
								
							
						
					
					
						commit
						b3b343ebf9
					
				
					 1 changed files with 10 additions and 0 deletions
				
			
		| 
						 | 
					@ -7,6 +7,7 @@ import (
 | 
				
			||||||
	"log"
 | 
						"log"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"net/http/httputil"
 | 
						"net/http/httputil"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
	"os/user"
 | 
						"os/user"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,6 +20,15 @@ func HomeDir() string {
 | 
				
			||||||
	return user.HomeDir
 | 
						return user.HomeDir
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Return true if `path` exists and false otherwise.
 | 
				
			||||||
 | 
					func FileExists(path string) bool {
 | 
				
			||||||
 | 
						if _, err := os.Stat(path); os.IsNotExist(err) {
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Call log.Fatal with `err` when it's not nil.
 | 
					// Call log.Fatal with `err` when it's not nil.
 | 
				
			||||||
func FailOn(err error) {
 | 
					func FailOn(err error) {
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue