diff --git a/go-demo-4/account/account.go b/go-demo-4/account/account.go index dbcecaa..9a5ea9f 100644 --- a/go-demo-4/account/account.go +++ b/go-demo-4/account/account.go @@ -21,7 +21,7 @@ type Account struct { // метод вывода пароля func (acc *Account) Output() { c := color.New(color.FgRed, color.Italic, color.Bold) - c.Printf("password: %v, login: %v, URL: %v\n", acc.Password, acc.Login, acc.Url) + c.Printf("password: %v\nlogin: %v\nURL: %v\n", acc.Password, acc.Login, acc.Url) } // метод генерации пароля diff --git a/go-demo-4/account/vault.go b/go-demo-4/account/vault.go index a4cb7da..0bd1b78 100644 --- a/go-demo-4/account/vault.go +++ b/go-demo-4/account/vault.go @@ -73,10 +73,10 @@ func (vault *Vault) ToBytes() ([]byte, error) { return file, nil } -func (vault *VaultWithDb) FindAccountsByUrl(url string) []Account { +func (vault *VaultWithDb) FindAccounts(str string, checker func(Account, string) bool) []Account { var accounts []Account for _, account := range vault.Accounts { - isMatched := strings.Contains(account.Url, url) + isMatched := checker(account, str) if isMatched { accounts = append(accounts, account) } diff --git a/go-demo-4/main.go b/go-demo-4/main.go index 14b0041..b852ccc 100644 --- a/go-demo-4/main.go +++ b/go-demo-4/main.go @@ -5,6 +5,7 @@ import ( "password/account" "password/files" "password/output" + "strings" "github.com/fatih/color" ) @@ -49,8 +50,8 @@ Menu: } func findAccount(vault *account.VaultWithDb) { - url := PromptData([]string{"Введите URL для поиска: "}) - accounts := vault.FindAccountsByUrl(url) + url := PromptData([]string{"Введите URL для поиска"}) + accounts := vault.FindAccounts(url, checkUrl) if len(accounts) == 0 { color.Red("Аккаунт не найден!") } @@ -59,6 +60,10 @@ func findAccount(vault *account.VaultWithDb) { } } +func checkUrl(acc account.Account, str string) bool { + return strings.Contains(acc.Url, str) +} + func deleteAccount(vault *account.VaultWithDb) { url := PromptData([]string{"Введите URL для поиска: "}) isDeleted := vault.DeleteAccountByUrl(url)