user_posix.go 409 B

123456789101112131415161718192021222324
  1. // Package pq is a pure Go Postgres driver for the database/sql package.
  2. // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris rumprun
  3. package pq
  4. import (
  5. "os"
  6. "os/user"
  7. )
  8. func userCurrent() (string, error) {
  9. u, err := user.Current()
  10. if err == nil {
  11. return u.Username, nil
  12. }
  13. name := os.Getenv("USER")
  14. if name != "" {
  15. return name, nil
  16. }
  17. return "", ErrCouldNotDetectUsername
  18. }