Package user

import "os/user"
Overview
Index

Overview ▾

软件包用户允许按名称或ID查找用户帐户.

对于大多数Unix系统,此软件包具有将用户ID和组ID解析为名称的两种内部实现. 一种是用纯Go语言编写的,并解析/ etc / passwd和/ etc / group. 另一个基于cgo,并且依赖于标准C库(libc)例程,例如getpwuid_r和getgrnam_r.

当cgo可用时,默认情况下使用基于cgo的(libc支持的)代码. 可以使用osusergo build标记将其覆盖,该标记强制执行纯Go实施.

type Group 1.7

组代表用户分组.

在POSIX系统上,Gid包含一个十进制数字,代表组ID.

type Group struct {
    Gid  string // group ID
    Name string // group name
}

func LookupGroup 1.7

func LookupGroup(name string) (*Group, error)

LookupGroup通过名称查找组. 如果找不到该组,则返回的错误类型为UnknownGroupError.

func LookupGroupId 1.7

func LookupGroupId(gid string) (*Group, error)

LookupGroupId通过groupid查找一个组. 如果找不到该组,则返回的错误类型为UnknownGroupIdError.

type UnknownGroupError 1.7

当找不到组时,LookupGroup返回UnknownGroupError.

type UnknownGroupError string

func (UnknownGroupError) Error 1.7

func (e UnknownGroupError) Error() string

type UnknownGroupIdError 1.7

当找不到组时,LookupGroupId返回UnknownGroupIdError.

type UnknownGroupIdError string

func (UnknownGroupIdError) Error 1.7

func (e UnknownGroupIdError) Error() string

type UnknownUserError

当找不到用户时,Lookup将返回UnknownUserError.

type UnknownUserError string

func (UnknownUserError) Error

func (e UnknownUserError) Error() string

type UnknownUserIdError

当找不到用户时,LookupId返回UnknownUserIdError.

type UnknownUserIdError int

func (UnknownUserIdError) Error

func (e UnknownUserIdError) Error() string

type User

用户代表用户帐户.

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.
    Uid string
    // 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.
    Gid string
    // Username is the login name.
    Username string
    // 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.
    Name string
    // HomeDir is the path to the user's home directory (if they have one).
    HomeDir string
}

func Current

func Current() (*User, error)

当前返回当前用户.

第一次调用将缓存当前用户信息. 后续调用将返回缓存的值,并且不会将更改反映给当前用户.

func Lookup

func Lookup(username string) (*User, error)

查找通过用户名查找用户. 如果找不到用户,则返回的错误类型为UnknownUserError.

func LookupId

func LookupId(uid string) (*User, error)

LookupId通过用户ID查找用户. 如果找不到用户,则返回的错误类型为UnknownUserIdError.

func (*User) GroupIds 1.7

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

GroupIds返回用户所属的组ID的列表.

by  ICOPY.SITE