Files
.examples
.github
alerting
client
config
controller
core
docs
jsonpath
metric
pattern
security
storage
util
vendor
github.com
TwiN
beorn7
cespare
go-ping
golang
google
gorilla
kballard
lib
pq
oid
scram
.gitignore
LICENSE.md
README.md
TESTS.md
array.go
buf.go
conn.go
conn_go18.go
connector.go
copy.go
doc.go
encode.go
error.go
krb.go
notice.go
notify.go
rows.go
ssl.go
ssl_permissions.go
ssl_windows.go
url.go
user_other.go
user_posix.go
user_windows.go
uuid.go
mattn
matttproud
miekg
prometheus
remyoudompheng
wcharczuk
go.etcd.io
golang.org
google.golang.org
gopkg.in
lukechampine.com
modernc.org
modules.txt
watchdog
web
.dockerignore
.gitattributes
.gitignore
Dockerfile
LICENSE.md
Makefile
README.md
config.yaml
go.mod
go.sum
main.go
gatus/vendor/github.com/lib/pq/user_windows.go

28 lines
871 B
Go

// Package pq is a pure Go Postgres driver for the database/sql package.
package pq
import (
"path/filepath"
"syscall"
)
// Perform Windows user name lookup identically to libpq.
//
// The PostgreSQL code makes use of the legacy Win32 function
// GetUserName, and that function has not been imported into stock Go.
// GetUserNameEx is available though, the difference being that a
// wider range of names are available. To get the output to be the
// same as GetUserName, only the base (or last) component of the
// result is returned.
func userCurrent() (string, error) {
pw_name := make([]uint16, 128)
pwname_size := uint32(len(pw_name)) - 1
err := syscall.GetUserNameEx(syscall.NameSamCompatible, &pw_name[0], &pwname_size)
if err != nil {
return "", ErrCouldNotDetectUsername
}
s := syscall.UTF16ToString(pw_name)
u := filepath.Base(s)
return u, nil
}