передача функции как аргумента другой функции

This commit is contained in:
Archer Fox
2025-03-16 23:19:15 +03:00
parent 0a2a722620
commit d9e8b18c52
3 changed files with 10 additions and 5 deletions

View File

@@ -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)
}