package main import ( "fmt" "os/user" ) func main() { username := "newuser" password := "mypassword" group := "mygroup" u := &user.User{ Username: username, Password: password, Groups: []string{group}, } err := user.CreateUser(u) if err != nil { fmt.Println(err) } else { fmt.Println("User created successfully.") } }
package main import ( "fmt" "os/user" ) func main() { username := "myuser" u, err := user.Lookup(username) if err != nil { fmt.Println(err) } else { fmt.Println("Username:", u.Username) fmt.Println("Home directory:", u.HomeDir) fmt.Println("User ID:", u.Uid) } }Both examples use the `user` package from the standard library.