// Copyright 2011 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package userimportconst ( userFile = "/etc/passwd" groupFile = "/etc/group")var colon = []byte{':'}// Current returns the current user.//// The first call will cache the current user information.// Subsequent calls will return the cached value and will not reflect// changes to the current user.func () (*User, error) {cache.Do(func() { cache.u, cache.err = current() })ifcache.err != nil {returnnil, cache.err } := *cache.u// copyreturn &, nil}// cache of the current uservar cache struct {sync.Once u *User err error}// Lookup looks up a user by username. If the user cannot be found, the// returned error is of type [UnknownUserError].func ( string) (*User, error) {if , := Current(); == nil && .Username == {return , }returnlookupUser()}// LookupId looks up a user by userid. If the user cannot be found, the// returned error is of type [UnknownUserIdError].func ( string) (*User, error) {if , := Current(); == nil && .Uid == {return , }returnlookupUserId()}// LookupGroup looks up a group by name. If the group cannot be found, the// returned error is of type [UnknownGroupError].func ( string) (*Group, error) {returnlookupGroup()}// LookupGroupId looks up a group by groupid. If the group cannot be found, the// returned error is of type [UnknownGroupIdError].func ( string) (*Group, error) {returnlookupGroupId()}// GroupIds returns the list of group IDs that the user is a member of.func ( *User) () ([]string, error) {returnlistGroups()}
The pages are generated with Goldsv0.7.0-preview. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.