Movatterモバイル変換


[0]ホーム

URL:


user

packagestandard library
go1.25.5Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2025 License:BSD-3-ClauseImports:8Imported by:40,920

Details

Repository

cs.opensource.google/go/go

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

typeGroupadded ingo1.7

type Group struct {Gidstring// group IDNamestring// group name}

Group represents a grouping of users.

On POSIX systems Gid contains a decimal number representing the group ID.

funcLookupGroupadded ingo1.7

func LookupGroup(namestring) (*Group,error)

LookupGroup looks up a group by name. If the group cannot be found, thereturned error is of typeUnknownGroupError.

funcLookupGroupIdadded ingo1.7

func LookupGroupId(gidstring) (*Group,error)

LookupGroupId looks up a group by groupid. If the group cannot be found, thereturned error is of typeUnknownGroupIdError.

typeUnknownGroupErroradded ingo1.7

type UnknownGroupErrorstring

UnknownGroupError is returned byLookupGroup whena group cannot be found.

func (UnknownGroupError)Erroradded ingo1.7

func (eUnknownGroupError) Error()string

typeUnknownGroupIdErroradded ingo1.7

type UnknownGroupIdErrorstring

UnknownGroupIdError is returned byLookupGroupId whena group cannot be found.

func (UnknownGroupIdError)Erroradded ingo1.7

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

func Current() (*User,error)

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

func Lookup(usernamestring) (*User,error)

Lookup looks up a user by username. If the user cannot be found, thereturned error is of typeUnknownUserError.

funcLookupId

func LookupId(uidstring) (*User,error)

LookupId looks up a user by userid. If the user cannot be found, thereturned error is of typeUnknownUserIdError.

func (*User)GroupIdsadded ingo1.7

func (u *User) GroupIds() ([]string,error)

GroupIds returns the list of group IDs that the user is a member of.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp