12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- 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 IsSymlink(path string) bool {
- if !IsExist(path) {
- return false
- }
- fileInfo, err := os.Lstat(path)
- if err != nil {
- return false
- }
- return fileInfo.Mode()&os.ModeSymlink != 0
- }
- 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
- }
|