文字
分享

  • import "os/user"

  • Overview

  • Index

概观

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

Index

  • type Group

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

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

  • type UnknownGroupError

  • func (e UnknownGroupError) Error() string

  • type UnknownGroupIdError

  • func (e UnknownGroupIdError) Error() string

  • type UnknownUserError

  • func (e UnknownUserError) Error() string

  • type UnknownUserIdError

  • func (e UnknownUserIdError) Error() string

  • type User

  • func Current() (*User, error)

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

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

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

包文件

lookup.go lookup_stubs.go lookup_unix.go user.go

type Group

组代表一组用户。

在 POSIX 系统上, Gid 包含一个表示组 ID 的十进制数字。

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

func LookupGroup

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

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

func LookupGroupId

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

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

type UnknownGroupError

当找不到组时,LookGroup 返回 UnknownGroupError 。

type UnknownGroupError string

func (UnknownGroupError) Error

func (e UnknownGroupError) Error() string

type UnknownGroupIdError

当找不到组时, LookGroupId 会返回 UnknownGroupIdError 。

type UnknownGroupIdError string

func (UnknownGroupIdError) Error

func (e UnknownGroupIdError) Error() string

type UnknownUserError

当找不到用户时,通过查找返回UnknownUserError。

type UnknownUserError string

func (UnknownUserError) Error

func (e UnknownUserError) Error() string

type UnknownUserIdError

UnknownUserIdError 由 LookupId 在找不到用户时返回。

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 通过用户名查找用户。如果找不到用户,返回的错误类型为 UnknownUserIdError 。

func (*User) GroupIds

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

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

上一篇:os/signal下一篇:path