package app import ( "fmt" "code.tnxs.net/taxnexus/lib/api/crm/crm_client/accounts" ) // GetAccount is first class retrieval function func GetAccount(key string, principal *User) Account { if key == "" { return Account{} } a, ok := accountCache.get(key) if ok { return *a } acct, err := GetAccountByID(key, principal) if err != nil { return Account{} } return acct } // GetAccountByID is first class retrieval function func GetAccountByID(recordID string, principal *User) (Account, error) { sugar.Debug("app.GetAccountByID: 📥") if recordID == "" { return Account{}, fmt.Errorf("app.getAccountByID: 💣 ⛔ key is blank") } obj, ok := accountCache.get(recordID) if ok { sugar.Debug("app.getAccountByID: 👍 🎯 📤") return *obj, nil } crmParams := accounts.NewGetAccountsParamsWithTimeout(getTimeout) crmParams.AccountID = &recordID response, err := crmClient.Accounts.GetAccounts(crmParams, principal.Auth) if err != nil { return Account{}, err } var newObj *Account for _, itm := range response.Payload.Data { // single iteration execution newObj = UnMarshalAccount(itm) } accountCache.put(recordID, newObj) sugar.Debug("app.getAccountByID: 👍 🆕 📤") return *newObj, nil }