Documentation
¶
Overview ¶
enchant with RunUser
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type User ¶
type User struct { Uid uint32 // user id Gid uint32 // primary group id Username string Name string HomeDir string }
func Lookup ¶
Example ¶
run user by username
package main import ( "os/exec" "os/user" "github.com/gnue/goutils/execuser" ) func isRootUser() bool { u, err := user.Current() if err != nil { return false } return u.Uid == "0" } func main() { cmd := exec.Command("ps", "u") if isRootUser() { if u, err := execuser.Lookup("username"); err == nil { u.RunUser(cmd) } } cmd.Run() }
Output:
func LookupPath ¶
Example ¶
run user by path
package main import ( "os/exec" "os/user" "github.com/gnue/goutils/execuser" ) func isRootUser() bool { u, err := user.Current() if err != nil { return false } return u.Uid == "0" } func main() { cmd := exec.Command("ps", "u") if isRootUser() { if u, err := execuser.LookupPath("."); err == nil { u.RunUser(cmd) } } cmd.Run() }
Output:
func (*User) SysProcAttr ¶
func (u *User) SysProcAttr() *syscall.SysProcAttr
Click to show internal directories.
Click to hide internal directories.