...
Source file
src/os/user/lookup.go
Documentation: os/user
1
2
3
4
5 package user
6
7 import "sync"
8
9
10
11
12
13
14 func Current() (*User, error) {
15 cache.Do(func() { cache.u, cache.err = current() })
16 if cache.err != nil {
17 return nil, cache.err
18 }
19 u := *cache.u
20 return &u, nil
21 }
22
23
24 var cache struct {
25 sync.Once
26 u *User
27 err error
28 }
29
30
31
32 func Lookup(username string) (*User, error) {
33 if u, err := Current(); err == nil && u.Username == username {
34 return u, err
35 }
36 return lookupUser(username)
37 }
38
39
40
41 func LookupId(uid string) (*User, error) {
42 if u, err := Current(); err == nil && u.Uid == uid {
43 return u, err
44 }
45 return lookupUserId(uid)
46 }
47
48
49
50 func LookupGroup(name string) (*Group, error) {
51 return lookupGroup(name)
52 }
53
54
55
56 func LookupGroupId(gid string) (*Group, error) {
57 return lookupGroupId(gid)
58 }
59
60
61 func (u *User) GroupIds() ([]string, error) {
62 return listGroups(u)
63 }
64
View as plain text