当前位置: 首页>>代码示例>>Golang>>正文


Golang Reader.SetString方法代码示例

本文整理汇总了Golang中io.Reader.SetString方法的典型用法代码示例。如果您正苦于以下问题:Golang Reader.SetString方法的具体用法?Golang Reader.SetString怎么用?Golang Reader.SetString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.Reader的用法示例。


在下文中一共展示了Reader.SetString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ImportGnucash


//.........这里部分代码省略.........
			rootAccount = gncxml.Accounts[i]
		} else {
			accountMap[gncxml.Accounts[i].AccountId] = gncxml.Accounts[i]
		}
	}

	//Translate to our account format, figuring out parent relationships
	for guid := range accountMap {
		ga := accountMap[guid]
		var a Account

		a.AccountId = ga.accountid
		if ga.ParentAccountId == rootAccount.AccountId {
			a.ParentAccountId = -1
		} else {
			parent, ok := accountMap[ga.ParentAccountId]
			if ok {
				a.ParentAccountId = parent.accountid
			} else {
				a.ParentAccountId = -1 // Ugly, but assign to top-level if we can't find its parent
			}
		}
		a.Name = ga.Name
		security, ok := securityMap[ga.Commodity.Name]
		if ok {
		} else {
			return nil, fmt.Errorf("Unable to find security: %s", ga.Commodity.Name)
		}
		a.SecurityId = security.SecurityId

		//TODO find account types
		switch ga.Type {
		default:
			a.Type = Bank
		case "ASSET":
			a.Type = Asset
		case "BANK":
			a.Type = Bank
		case "CASH":
			a.Type = Cash
		case "CREDIT", "LIABILITY":
			a.Type = Liability
		case "EQUITY":
			a.Type = Equity
		case "EXPENSE":
			a.Type = Expense
		case "INCOME":
			a.Type = Income
		case "PAYABLE":
			a.Type = Payable
		case "RECEIVABLE":
			a.Type = Receivable
		case "MUTUAL", "STOCK":
			a.Type = Investment
		case "TRADING":
			a.Type = Trading
		}

		gncimport.Accounts = append(gncimport.Accounts, a)
	}

	//Translate transactions to our format
	for i := range gncxml.Transactions {
		gt := gncxml.Transactions[i]

		t := new(Transaction)
		t.Description = gt.Description
		t.Date = gt.DatePosted.Date.Time
		t.Status = Imported
		for j := range gt.Splits {
			gs := gt.Splits[j]
			s := new(Split)
			s.Memo = gs.Memo
			account, ok := accountMap[gs.AccountId]
			if !ok {
				return nil, fmt.Errorf("Unable to find account: %s", gs.AccountId)
			}
			s.AccountId = account.accountid

			security, ok := securityMap[account.Commodity.Name]
			if !ok {
				return nil, fmt.Errorf("Unable to find security: %s", account.Commodity.Name)
			}
			s.SecurityId = -1

			var r big.Rat
			_, ok = r.SetString(gs.Amount)
			if ok {
				s.Amount = r.FloatString(security.Precision)
			} else {
				return nil, fmt.Errorf("Can't set split Amount: %s", gs.Amount)
			}

			t.Splits = append(t.Splits, s)
		}
		gncimport.Transactions = append(gncimport.Transactions, *t)
	}

	return &gncimport, nil
}
开发者ID:aclindsa,项目名称:moneygo,代码行数:101,代码来源:gnucash.go


注:本文中的io.Reader.SetString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。