Files
purpleschool/go-demo-4/main.go
2025-03-08 21:18:39 +03:00

68 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"fmt"
"password/account"
"github.com/fatih/color"
)
func main() {
fmt.Println("__Менеджер паролей__")
vault := account.NewVault()
Menu:
for {
variant := getMenu()
switch variant {
case 1:
createAccount(vault)
case 2:
findAccount(vault)
case 3:
deleteAccount()
default:
break Menu
}
}
}
func getMenu() int {
var variant int
fmt.Println("Выберите вариант:")
fmt.Println("1. Создать аккаунт")
fmt.Println("2. Найти аккаунт")
fmt.Println("3. Удалить аккаунт")
fmt.Println("4. Выход")
fmt.Scan(&variant)
return variant
}
func findAccount(vault *account.Vault) {
url := account.PromptData("Введите URL для поиска: ")
accounts := vault.FindAccountsByUrl(url)
if len(accounts) == 0 {
color.Red("Аккаунт не найден!")
}
for _, account := range accounts {
account.Output()
}
}
func deleteAccount() {
}
func createAccount(vault *account.Vault) {
login := account.PromptData("Введите логин: ")
password := account.PromptData("Введите пароль: ")
url := account.PromptData("Введите URL: ")
myAccount, err := account.NewAccount(login, password, url)
if err != nil {
fmt.Println("ОШИБКА: Неверный формат URL")
return
}
vault = account.NewVault()
vault.AddAccount(*myAccount)
}