ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# package user `import "os/user"` user包允许通过名称或ID查询用户帐户。 ## Index * [type UnknownUserError](#UnknownUserError) * [func (e UnknownUserError) Error() string](#UnknownUserError.Error) * [type UnknownUserIdError](#UnknownUserIdError) * [func (e UnknownUserIdError) Error() string](#UnknownUserIdError.Error) * [type User](#User) * [func Current() (\*User, error)](#Current) * [func Lookup(username string) (\*User, error)](#Lookup) * [func LookupId(uid string) (\*User, error)](#LookupId) ## type [UnknownUserError](https://github.com/golang/go/blob/master/src/os/user/user.go#L39 "View Source") ``` type UnknownUserError string ``` 当找不到用户时,Lookup会返回UnknownUserError ### func (UnknownUserError) [Error](https://github.com/golang/go/blob/master/src/os/user/user.go#L41 "View Source") ``` func (e UnknownUserError) Error() string ``` ## type [UnknownUserIdError](https://github.com/golang/go/blob/master/src/os/user/user.go#L31 "View Source") ``` type UnknownUserIdError int ``` 当找不到用户时,LookupId会返回UnknownUserIdError ### func (UnknownUserIdError) [Error](https://github.com/golang/go/blob/master/src/os/user/user.go#L33 "View Source") ``` func (e UnknownUserIdError) Error() string ``` ## type [User](https://github.com/golang/go/blob/master/src/os/user/user.go#L21 "View Source") ``` type User struct { Uid string // 用户ID Gid string // 初级组ID Username string Name string HomeDir string } ``` User代表一个用户帐户。 在posix系统中Uid和Gid字段分别包含代表uid和gid的十进制数字。在windows系统中Uid和Gid包含字符串格式的安全标识符(SID)。在Plan 9系统中,Uid、Gid、Username和Name字段是/dev/user的内容。 ### func [Current](https://github.com/golang/go/blob/master/src/os/user/lookup.go#L8 "View Source") ``` func Current() (*User, error) ``` 返回当前的用户帐户。 ### func [Lookup](https://github.com/golang/go/blob/master/src/os/user/lookup.go#L14 "View Source") ``` func Lookup(username string) (*User, error) ``` 根据用户名查询用户。 ### func [LookupId](https://github.com/golang/go/blob/master/src/os/user/lookup.go#L20 "View Source") ``` func LookupId(uid string) (*User, error) ``` 根据用户ID查询用户。