user
packagestandard libraryThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package user allows user account lookups by name or id.
For most Unix systems, this package has two internal implementations ofresolving user and group ids to names, and listing supplementary group IDs.One is written in pure Go and parses /etc/passwd and /etc/group. The otheris cgo-based and relies on the standard C library (libc) routines such asgetpwuid_r, getgrnam_r, and getgrouplist.
When cgo is available, and the required routines are implemented in libcfor a particular platform, cgo-based (libc-backed) code is used.This can be overridden by using osusergo build tag, which enforcesthe pure Go implementation.
Index¶
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
This section is empty.
Types¶
typeGroup¶added ingo1.7
Group represents a grouping of users.
On POSIX systems Gid contains a decimal number representing the group ID.
funcLookupGroup¶added ingo1.7
LookupGroup looks up a group by name. If the group cannot be found, thereturned error is of typeUnknownGroupError.
funcLookupGroupId¶added ingo1.7
LookupGroupId looks up a group by groupid. If the group cannot be found, thereturned error is of typeUnknownGroupIdError.
typeUnknownGroupError¶added ingo1.7
type UnknownGroupErrorstring
UnknownGroupError is returned byLookupGroup whena group cannot be found.
func (UnknownGroupError)Error¶added ingo1.7
func (eUnknownGroupError) Error()string
typeUnknownGroupIdError¶added ingo1.7
type UnknownGroupIdErrorstring
UnknownGroupIdError is returned byLookupGroupId whena group cannot be found.
func (UnknownGroupIdError)Error¶added ingo1.7
func (eUnknownGroupIdError) Error()string
typeUnknownUserError¶
type UnknownUserErrorstring
UnknownUserError is returned byLookup whena user cannot be found.
func (UnknownUserError)Error¶
func (eUnknownUserError) Error()string
typeUnknownUserIdError¶
type UnknownUserIdErrorint
UnknownUserIdError is returned byLookupId when a user cannot be found.
func (UnknownUserIdError)Error¶
func (eUnknownUserIdError) Error()string
typeUser¶
type User struct {// Uid is the user ID.// On POSIX systems, this is a decimal number representing the uid.// On Windows, this is a security identifier (SID) in a string format.// On Plan 9, this is the contents of /dev/user.Uidstring// Gid is the primary group ID.// On POSIX systems, this is a decimal number representing the gid.// On Windows, this is a SID in a string format.// On Plan 9, this is the contents of /dev/user.Gidstring// Username is the login name.Usernamestring// Name is the user's real or display name.// It might be blank.// On POSIX systems, this is the first (or only) entry in the GECOS field// list.// On Windows, this is the user's display name.// On Plan 9, this is the contents of /dev/user.Namestring// HomeDir is the path to the user's home directory (if they have one).HomeDirstring}User represents a user account.
funcCurrent¶
Current returns the current user.
The first call will cache the current user information.Subsequent calls will return the cached value and will not reflectchanges to the current user.
funcLookup¶
Lookup looks up a user by username. If the user cannot be found, thereturned error is of typeUnknownUserError.
funcLookupId¶
LookupId looks up a user by userid. If the user cannot be found, thereturned error is of typeUnknownUserIdError.