This is a creation in Article, where the information may have evolved or changed.
Os/user package allows user accounts to find users by user name or user ID
Type Unknownusererror
Type Unknownusererror string
Func (e unknownusererror) error () string//When a user cannot be found through lookup, the error is returned. Type Unknownuseriderror
Type Unknownuseriderror int
Func (e unknownuseriderror) error () string////returns the error when a user ID cannot be found through lookup.
Type User
Type user struct {Uid string//User Idgid string//Primary group Idusername string Name stringhomedir
string //Household Directory}
Func current () (*user, error)//Getting information about the user
Func lookup (Username string) (*user, error)//Find user information by user name
Func lookupid (UID string) (*user, error)//Find user information based on user ID.
Func main () {usr, err: = user. Current () if err! = Nil {fmt. PRINTLN (Err)}fmt. Println (usr. Gid) fmt. Println (usr. Homedir) fmt. Println (usr. Name) fmt. Println (usr. Uid) fmt. Println (usr. Username) usr, _ = user. Lookup ("root")//based on user name, find the users fmt. Println (usr) usr, err = user. LookupId ("1100")//Find user FMT based on UserID. Println (usr, err)}