File: user_posix.go

package info (click to toggle)
golang-github-lib-pq 1.10.9-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 724 kB
  • sloc: makefile: 35; sh: 14
file content (25 lines) | stat: -rw-r--r-- 579 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Package pq is a pure Go Postgres driver for the database/sql package.

//go:build aix || darwin || dragonfly || freebsd || (linux && !android) || nacl || netbsd || openbsd || plan9 || solaris || rumprun || illumos
// +build aix darwin dragonfly freebsd linux,!android nacl netbsd openbsd plan9 solaris rumprun illumos

package pq

import (
	"os"
	"os/user"
)

func userCurrent() (string, error) {
	u, err := user.Current()
	if err == nil {
		return u.Username, nil
	}

	name := os.Getenv("USER")
	if name != "" {
		return name, nil
	}

	return "", ErrCouldNotDetectUsername
}