1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package osutil
- import (
- "os"
- "os/user"
- )
- func IsFile(path string) bool {
- f, e := os.Stat(path)
- if e != nil {
- return false
- }
- return !f.IsDir()
- }
- func IsDir(dir string) bool {
- f, e := os.Stat(dir)
- if e != nil {
- return false
- }
- return f.IsDir()
- }
- func IsExist(path string) bool {
- _, err := os.Stat(path)
- return err == nil || os.IsExist(err)
- }
- func CurrentUsername() string {
- username := os.Getenv("USER")
- if len(username) > 0 {
- return username
- }
- username = os.Getenv("USERNAME")
- if len(username) > 0 {
- return username
- }
- if user, err := user.Current(); err == nil {
- username = user.Username
- }
- return username
- }
|