...

Source file src/github.com/lib/pq/user_posix.go

Documentation: github.com/lib/pq

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

View as plain text