Support utils.HomeDir/0
Support function for returning the home directory of the current user.
This commit is contained in:
		
							parent
							
								
									825d6f2c65
								
							
						
					
					
						commit
						3ae3b6f039
					
				
					 1 changed files with 10 additions and 0 deletions
				
			
		|  | @ -7,8 +7,18 @@ import ( | ||||||
| 	"log" | 	"log" | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"net/http/httputil" | 	"net/http/httputil" | ||||||
|  | 	"os/user" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | // Return the absolute path to the current uesr's home directory. | ||||||
|  | func HomeDir() string { | ||||||
|  | 	user, err := user.Current() | ||||||
|  | 	if err != nil { | ||||||
|  | 		log.Fatal(err) | ||||||
|  | 	} | ||||||
|  | 	return user.HomeDir | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // 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