passwduser

package module
v0.0.0-...-9bf69c2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2016 License: MIT Imports: 6 Imported by: 4

README

Godoc Go Report Card Build Status

A cgo-free implementation of os/user that parses /etc/passwd

Golang's os/user is a great package that provides an API to access information for the current user/group. However, the Unix implementation relies in cgo since it uses getpwuid [1] to obtain the user/group information. This library is avoiding that by parsing the /etc/passwd file instead.

NOTICE this may not be enough for your application. getpwuid does also use LDAP and NIS databases to obtain the user information. If your system uses one of these technologies, this implementation is not for you and you unfortunately have to use cgo.

Work in progress

This package is currently only implementing the following methods:

  • Current() (*User, error)
  • Lookup(username string) (*User, error)
  • LookupId(uid string) (*User, error)

It does not yet implement:

  • (*User) GroupIds() ([]string, error)
  • LookupGroup(name string) (*Group, error)
  • LookupGroupId(gid string) (*Group, error)

[1] https://linux.die.net/man/3/getpwuid

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type User

type User struct {
	UID      string // user ID
	GID      string // primary group ID
	Username string
	Name     string
	HomeDir  string
}

User represents a user account.

func Current

func Current() (*User, error)

Current finds and returns the current user.

func Lookup

func Lookup(username string) (*User, error)

Lookup finds a user by her username.

func LookupID

func LookupID(uid string) (*User, error)

LookupID finds a user by her UID.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL