...
Run Format

Source file src/os/user/user.go

Documentation: os/user

     1  // Copyright 2011 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package user allows user account lookups by name or id.
     6  package user
     7  
     8  import (
     9  	"strconv"
    10  )
    11  
    12  var (
    13  	userImplemented  = true // set to false by lookup_stubs.go's init
    14  	groupImplemented = true // set to false by lookup_stubs.go's init
    15  )
    16  
    17  // User represents a user account.
    18  type User struct {
    19  	// Uid is the user ID.
    20  	// On POSIX systems, this is a decimal number representing the uid.
    21  	// On Windows, this is a security identifier (SID) in a string format.
    22  	// On Plan 9, this is the contents of /dev/user.
    23  	Uid string
    24  	// Gid is the primary group ID.
    25  	// On POSIX systems, this is a decimal number representing the gid.
    26  	// On Windows, this is a SID in a string format.
    27  	// On Plan 9, this is the contents of /dev/user.
    28  	Gid string
    29  	// Username is the login name.
    30  	Username string
    31  	// Name is the user's real or display name.
    32  	// It might be blank.
    33  	// On POSIX systems, this is the first (or only) entry in the GECOS field
    34  	// list.
    35  	// On Windows, this is the user's display name.
    36  	// On Plan 9, this is the contents of /dev/user.
    37  	Name string
    38  	// HomeDir is the path to the user's home directory (if they have one).
    39  	HomeDir string
    40  }
    41  
    42  // Group represents a grouping of users.
    43  //
    44  // On POSIX systems Gid contains a decimal number representing the group ID.
    45  type Group struct {
    46  	Gid  string // group ID
    47  	Name string // group name
    48  }
    49  
    50  // UnknownUserIdError is returned by LookupId when a user cannot be found.
    51  type UnknownUserIdError int
    52  
    53  func (e UnknownUserIdError) Error() string {
    54  	return "user: unknown userid " + strconv.Itoa(int(e))
    55  }
    56  
    57  // UnknownUserError is returned by Lookup when
    58  // a user cannot be found.
    59  type UnknownUserError string
    60  
    61  func (e UnknownUserError) Error() string {
    62  	return "user: unknown user " + string(e)
    63  }
    64  
    65  // UnknownGroupIdError is returned by LookupGroupId when
    66  // a group cannot be found.
    67  type UnknownGroupIdError string
    68  
    69  func (e UnknownGroupIdError) Error() string {
    70  	return "group: unknown groupid " + string(e)
    71  }
    72  
    73  // UnknownGroupError is returned by LookupGroup when
    74  // a group cannot be found.
    75  type UnknownGroupError string
    76  
    77  func (e UnknownGroupError) Error() string {
    78  	return "group: unknown group " + string(e)
    79  }
    80  

View as plain text