Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListAll ¶
func ListAll(filters ...UserFilter) ([]*user.User, error)
读取 `/etc/passwd` 文件,获得所有用户的信息
可以通过设置 UserFilter 来对用户进行过滤
Example ¶
users, err := ListAll(func(user *user.User) bool { return len(user.HomeDir) > 4 && user.HomeDir[:5] == "/home" }) if err != nil { return } if len(users) == 0 { return } rlt, _ := json.MarshalIndent(users, "", " ") fmt.Println(string(rlt))
Output:
Types ¶
type LoggedUser ¶
func ListLogged ¶
func ListLogged() ([]*LoggedUser, error)
读取 `/var/run/utmp` 文件,获得登陆用户的信息
Example ¶
loginUsers, err := ListLogged() if err != nil { return } rlt, _ := json.MarshalIndent(loginUsers, "", " ") fmt.Println(string(rlt))
Output:
type UserFilter ¶
Click to show internal directories.
Click to hide internal directories.