osutil.go 612 B

12345678910111213141516171819202122232425262728
  1. // Copyright 2020 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package osutil
  5. import (
  6. "os"
  7. )
  8. // IsFile returns true if given path exists as a file (i.e. not a directory).
  9. func IsFile(path string) bool {
  10. f, e := os.Stat(path)
  11. if e != nil {
  12. return false
  13. }
  14. return !f.IsDir()
  15. }
  16. // CurrentUsername returns the current system user via environment variables.
  17. func CurrentUsername() string {
  18. curUserName := os.Getenv("USER")
  19. if len(curUserName) > 0 {
  20. return curUserName
  21. }
  22. return os.Getenv("USERNAME")
  23. }