func main() { fmt.Print("Enter the password: "******"The password is %q.\n", password) }
func passwordFromReader(reader io.Reader) (string, error) { var ( password string err error ) if file, ok := reader.(*os.File); ok { password, err = term.ReadPassword(file.Fd()) if err != nil { return "", err } } else { fmt.Fscanf(reader, "%s\n", &password) } if password == "" { msg := "You must provide the password!" return "", errors.New(msg) } return password, err }