首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

os/user

  • 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)

包文件

组代表一组用户。

在 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 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() (*User, error)

当前返回当前用户。

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

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

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

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

func (*User) GroupIds(显示源文件)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券