1
0
mirror of https://github.com/aclindsa/ofxgo.git synced 2024-11-22 11:30:05 -05:00

Add a few more comments

This commit is contained in:
Aaron Lindsay 2017-04-11 06:08:40 -04:00
parent d6aa6608e7
commit a05882fcda
3 changed files with 90 additions and 3 deletions

View File

@ -216,6 +216,8 @@ var statusMeanings = map[Int][3]string{
16503: {"Unable to get URL", "ERROR", "The server was unable to retrieve the information at this URL (e.g., an HTTP 400 or 500 series error)."}, 16503: {"Unable to get URL", "ERROR", "The server was unable to retrieve the information at this URL (e.g., an HTTP 400 or 500 series error)."},
} }
// Status represents the status of a Response (both top-level Request objects,
// and *Response objects)
type Status struct { type Status struct {
XMLName xml.Name `xml:"STATUS"` XMLName xml.Name `xml:"STATUS"`
Code Int `xml:"CODE"` Code Int `xml:"CODE"`
@ -223,6 +225,7 @@ type Status struct {
Message String `xml:"MESSAGE,omitempty"` Message String `xml:"MESSAGE,omitempty"`
} }
// Valid returns whether the Status is valid according to the OFX spec
func (s *Status) Valid() (bool, error) { func (s *Status) Valid() (bool, error) {
switch s.Severity { switch s.Severity {
case "INFO", "WARN", "ERROR": case "INFO", "WARN", "ERROR":
@ -241,7 +244,7 @@ func (s *Status) Valid() (bool, error) {
return true, nil return true, nil
} }
// Return the meaning of the current status Code // CodeMeaning returns the meaning of the current status Code
func (s *Status) CodeMeaning() (string, error) { func (s *Status) CodeMeaning() (string, error) {
if arr, ok := statusMeanings[s.Code]; ok { if arr, ok := statusMeanings[s.Code]; ok {
return arr[0], nil return arr[0], nil
@ -249,8 +252,8 @@ func (s *Status) CodeMeaning() (string, error) {
return "", errors.New("Unknown OFX status code") return "", errors.New("Unknown OFX status code")
} }
// Return the conditions under which an OFX server is expected to return the // CodeConditions returns the conditions under which an OFX server is expected
// current status Code // to return the current status Code
func (s *Status) CodeConditions() (string, error) { func (s *Status) CodeConditions() (string, error) {
if arr, ok := statusMeanings[s.Code]; ok { if arr, ok := statusMeanings[s.Code]; ok {
return arr[2], nil return arr[2], nil
@ -258,6 +261,7 @@ func (s *Status) CodeConditions() (string, error) {
return "", errors.New("Unknown OFX status code") return "", errors.New("Unknown OFX status code")
} }
// BankAcct represents the identifying information for one bank account
type BankAcct struct { type BankAcct struct {
XMLName xml.Name // BANKACCTTO or BANKACCTFROM XMLName xml.Name // BANKACCTTO or BANKACCTFROM
BankId String `xml:"BANKID"` BankId String `xml:"BANKID"`
@ -267,18 +271,21 @@ type BankAcct struct {
AcctKey String `xml:"ACCTKEY,omitempty"` // Unused in USA AcctKey String `xml:"ACCTKEY,omitempty"` // Unused in USA
} }
// CCAcct represents the identifying information for one checking account
type CCAcct struct { type CCAcct struct {
XMLName xml.Name // CCACCTTO or CCACCTFROM XMLName xml.Name // CCACCTTO or CCACCTFROM
AcctId String `xml:"ACCTID"` AcctId String `xml:"ACCTID"`
AcctKey String `xml:"ACCTKEY,omitempty"` // Unused in USA AcctKey String `xml:"ACCTKEY,omitempty"` // Unused in USA
} }
// InvAcct represents the identifying information for one investment account
type InvAcct struct { type InvAcct struct {
XMLName xml.Name // INVACCTTO or INVACCTFROM XMLName xml.Name // INVACCTTO or INVACCTFROM
BrokerId String `xml:"BROKERID"` BrokerId String `xml:"BROKERID"`
AcctId String `xml:"ACCTID"` AcctId String `xml:"ACCTID"`
} }
// Currency represents one ISO-4217 currency
type Currency struct { type Currency struct {
XMLName xml.Name // CURRENCY or ORIGCURRENCY XMLName xml.Name // CURRENCY or ORIGCURRENCY
CurRate Amount `xml:"CURRATE"` // Ratio of <CURDEF> currency to <CURSYM> currency CurRate Amount `xml:"CURRATE"` // Ratio of <CURDEF> currency to <CURSYM> currency

View File

@ -69,6 +69,8 @@ func (e *acctType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
return nil return nil
} }
// NewAcctType returns returns an 'enum' value of type acctType given its
// string representation
func NewAcctType(s string) (acctType, error) { func NewAcctType(s string) (acctType, error) {
var e acctType var e acctType
err := e.FromString(s) err := e.FromString(s)
@ -147,6 +149,8 @@ func (e *trnType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
return nil return nil
} }
// NewTrnType returns returns an 'enum' value of type trnType given its
// string representation
func NewTrnType(s string) (trnType, error) { func NewTrnType(s string) (trnType, error) {
var e trnType var e trnType
err := e.FromString(s) err := e.FromString(s)
@ -210,6 +214,8 @@ func (e *imageType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
return nil return nil
} }
// NewImageType returns returns an 'enum' value of type imageType given its
// string representation
func NewImageType(s string) (imageType, error) { func NewImageType(s string) (imageType, error) {
var e imageType var e imageType
err := e.FromString(s) err := e.FromString(s)
@ -273,6 +279,8 @@ func (e *imageRefType) MarshalXML(enc *xml.Encoder, start xml.StartElement) erro
return nil return nil
} }
// NewImageRefType returns returns an 'enum' value of type imageRefType given its
// string representation
func NewImageRefType(s string) (imageRefType, error) { func NewImageRefType(s string) (imageRefType, error) {
var e imageRefType var e imageRefType
err := e.FromString(s) err := e.FromString(s)
@ -336,6 +344,8 @@ func (e *checkSup) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
return nil return nil
} }
// NewCheckSup returns returns an 'enum' value of type checkSup given its
// string representation
func NewCheckSup(s string) (checkSup, error) { func NewCheckSup(s string) (checkSup, error) {
var e checkSup var e checkSup
err := e.FromString(s) err := e.FromString(s)
@ -398,6 +408,8 @@ func (e *correctAction) MarshalXML(enc *xml.Encoder, start xml.StartElement) err
return nil return nil
} }
// NewCorrectAction returns returns an 'enum' value of type correctAction given its
// string representation
func NewCorrectAction(s string) (correctAction, error) { func NewCorrectAction(s string) (correctAction, error) {
var e correctAction var e correctAction
err := e.FromString(s) err := e.FromString(s)
@ -461,6 +473,8 @@ func (e *balType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
return nil return nil
} }
// NewBalType returns returns an 'enum' value of type balType given its
// string representation
func NewBalType(s string) (balType, error) { func NewBalType(s string) (balType, error) {
var e balType var e balType
err := e.FromString(s) err := e.FromString(s)
@ -528,6 +542,8 @@ func (e *inv401kSource) MarshalXML(enc *xml.Encoder, start xml.StartElement) err
return nil return nil
} }
// NewInv401kSource returns returns an 'enum' value of type inv401kSource given its
// string representation
func NewInv401kSource(s string) (inv401kSource, error) { func NewInv401kSource(s string) (inv401kSource, error) {
var e inv401kSource var e inv401kSource
err := e.FromString(s) err := e.FromString(s)
@ -592,6 +608,8 @@ func (e *subAcctType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error
return nil return nil
} }
// NewSubAcctType returns returns an 'enum' value of type subAcctType given its
// string representation
func NewSubAcctType(s string) (subAcctType, error) { func NewSubAcctType(s string) (subAcctType, error) {
var e subAcctType var e subAcctType
err := e.FromString(s) err := e.FromString(s)
@ -654,6 +672,8 @@ func (e *buyType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
return nil return nil
} }
// NewBuyType returns returns an 'enum' value of type buyType given its
// string representation
func NewBuyType(s string) (buyType, error) { func NewBuyType(s string) (buyType, error) {
var e buyType var e buyType
err := e.FromString(s) err := e.FromString(s)
@ -717,6 +737,8 @@ func (e *optAction) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
return nil return nil
} }
// NewOptAction returns returns an 'enum' value of type optAction given its
// string representation
func NewOptAction(s string) (optAction, error) { func NewOptAction(s string) (optAction, error) {
var e optAction var e optAction
err := e.FromString(s) err := e.FromString(s)
@ -779,6 +801,8 @@ func (e *tferAction) MarshalXML(enc *xml.Encoder, start xml.StartElement) error
return nil return nil
} }
// NewTferAction returns returns an 'enum' value of type tferAction given its
// string representation
func NewTferAction(s string) (tferAction, error) { func NewTferAction(s string) (tferAction, error) {
var e tferAction var e tferAction
err := e.FromString(s) err := e.FromString(s)
@ -841,6 +865,8 @@ func (e *posType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
return nil return nil
} }
// NewPosType returns returns an 'enum' value of type posType given its
// string representation
func NewPosType(s string) (posType, error) { func NewPosType(s string) (posType, error) {
var e posType var e posType
err := e.FromString(s) err := e.FromString(s)
@ -903,6 +929,8 @@ func (e *secured) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
return nil return nil
} }
// NewSecured returns returns an 'enum' value of type secured given its
// string representation
func NewSecured(s string) (secured, error) { func NewSecured(s string) (secured, error) {
var e secured var e secured
err := e.FromString(s) err := e.FromString(s)
@ -966,6 +994,8 @@ func (e *duration) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
return nil return nil
} }
// NewDuration returns returns an 'enum' value of type duration given its
// string representation
func NewDuration(s string) (duration, error) { func NewDuration(s string) (duration, error) {
var e duration var e duration
err := e.FromString(s) err := e.FromString(s)
@ -1029,6 +1059,8 @@ func (e *restriction) MarshalXML(enc *xml.Encoder, start xml.StartElement) error
return nil return nil
} }
// NewRestriction returns returns an 'enum' value of type restriction given its
// string representation
func NewRestriction(s string) (restriction, error) { func NewRestriction(s string) (restriction, error) {
var e restriction var e restriction
err := e.FromString(s) err := e.FromString(s)
@ -1091,6 +1123,8 @@ func (e *unitType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
return nil return nil
} }
// NewUnitType returns returns an 'enum' value of type unitType given its
// string representation
func NewUnitType(s string) (unitType, error) { func NewUnitType(s string) (unitType, error) {
var e unitType var e unitType
err := e.FromString(s) err := e.FromString(s)
@ -1153,6 +1187,8 @@ func (e *optBuyType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error
return nil return nil
} }
// NewOptBuyType returns returns an 'enum' value of type optBuyType given its
// string representation
func NewOptBuyType(s string) (optBuyType, error) { func NewOptBuyType(s string) (optBuyType, error) {
var e optBuyType var e optBuyType
err := e.FromString(s) err := e.FromString(s)
@ -1215,6 +1251,8 @@ func (e *sellType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
return nil return nil
} }
// NewSellType returns returns an 'enum' value of type sellType given its
// string representation
func NewSellType(s string) (sellType, error) { func NewSellType(s string) (sellType, error) {
var e sellType var e sellType
err := e.FromString(s) err := e.FromString(s)
@ -1285,6 +1323,8 @@ func (e *loanPmtFreq) MarshalXML(enc *xml.Encoder, start xml.StartElement) error
return nil return nil
} }
// NewLoanPmtFreq returns returns an 'enum' value of type loanPmtFreq given its
// string representation
func NewLoanPmtFreq(s string) (loanPmtFreq, error) { func NewLoanPmtFreq(s string) (loanPmtFreq, error) {
var e loanPmtFreq var e loanPmtFreq
err := e.FromString(s) err := e.FromString(s)
@ -1350,6 +1390,8 @@ func (e *incomeType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error
return nil return nil
} }
// NewIncomeType returns returns an 'enum' value of type incomeType given its
// string representation
func NewIncomeType(s string) (incomeType, error) { func NewIncomeType(s string) (incomeType, error) {
var e incomeType var e incomeType
err := e.FromString(s) err := e.FromString(s)
@ -1413,6 +1455,8 @@ func (e *sellReason) MarshalXML(enc *xml.Encoder, start xml.StartElement) error
return nil return nil
} }
// NewSellReason returns returns an 'enum' value of type sellReason given its
// string representation
func NewSellReason(s string) (sellReason, error) { func NewSellReason(s string) (sellReason, error) {
var e sellReason var e sellReason
err := e.FromString(s) err := e.FromString(s)
@ -1475,6 +1519,8 @@ func (e *optSellType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error
return nil return nil
} }
// NewOptSellType returns returns an 'enum' value of type optSellType given its
// string representation
func NewOptSellType(s string) (optSellType, error) { func NewOptSellType(s string) (optSellType, error) {
var e optSellType var e optSellType
err := e.FromString(s) err := e.FromString(s)
@ -1539,6 +1585,8 @@ func (e *relType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
return nil return nil
} }
// NewRelType returns returns an 'enum' value of type relType given its
// string representation
func NewRelType(s string) (relType, error) { func NewRelType(s string) (relType, error) {
var e relType var e relType
err := e.FromString(s) err := e.FromString(s)
@ -1603,6 +1651,8 @@ func (e *charType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
return nil return nil
} }
// NewCharType returns returns an 'enum' value of type charType given its
// string representation
func NewCharType(s string) (charType, error) { func NewCharType(s string) (charType, error) {
var e charType var e charType
err := e.FromString(s) err := e.FromString(s)
@ -1665,6 +1715,8 @@ func (e *syncMode) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
return nil return nil
} }
// NewSyncMode returns returns an 'enum' value of type syncMode given its
// string representation
func NewSyncMode(s string) (syncMode, error) { func NewSyncMode(s string) (syncMode, error) {
var e syncMode var e syncMode
err := e.FromString(s) err := e.FromString(s)
@ -1727,6 +1779,8 @@ func (e *debtType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
return nil return nil
} }
// NewDebtType returns returns an 'enum' value of type debtType given its
// string representation
func NewDebtType(s string) (debtType, error) { func NewDebtType(s string) (debtType, error) {
var e debtType var e debtType
err := e.FromString(s) err := e.FromString(s)
@ -1791,6 +1845,8 @@ func (e *debtClass) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
return nil return nil
} }
// NewDebtClass returns returns an 'enum' value of type debtClass given its
// string representation
func NewDebtClass(s string) (debtClass, error) { func NewDebtClass(s string) (debtClass, error) {
var e debtClass var e debtClass
err := e.FromString(s) err := e.FromString(s)
@ -1856,6 +1912,8 @@ func (e *couponFreq) MarshalXML(enc *xml.Encoder, start xml.StartElement) error
return nil return nil
} }
// NewCouponFreq returns returns an 'enum' value of type couponFreq given its
// string representation
func NewCouponFreq(s string) (couponFreq, error) { func NewCouponFreq(s string) (couponFreq, error) {
var e couponFreq var e couponFreq
err := e.FromString(s) err := e.FromString(s)
@ -1920,6 +1978,8 @@ func (e *callType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
return nil return nil
} }
// NewCallType returns returns an 'enum' value of type callType given its
// string representation
func NewCallType(s string) (callType, error) { func NewCallType(s string) (callType, error) {
var e callType var e callType
err := e.FromString(s) err := e.FromString(s)
@ -1987,6 +2047,8 @@ func (e *assetClass) MarshalXML(enc *xml.Encoder, start xml.StartElement) error
return nil return nil
} }
// NewAssetClass returns returns an 'enum' value of type assetClass given its
// string representation
func NewAssetClass(s string) (assetClass, error) { func NewAssetClass(s string) (assetClass, error) {
var e assetClass var e assetClass
err := e.FromString(s) err := e.FromString(s)
@ -2050,6 +2112,8 @@ func (e *mfType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
return nil return nil
} }
// NewMfType returns returns an 'enum' value of type mfType given its
// string representation
func NewMfType(s string) (mfType, error) { func NewMfType(s string) (mfType, error) {
var e mfType var e mfType
err := e.FromString(s) err := e.FromString(s)
@ -2112,6 +2176,8 @@ func (e *optType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
return nil return nil
} }
// NewOptType returns returns an 'enum' value of type optType given its
// string representation
func NewOptType(s string) (optType, error) { func NewOptType(s string) (optType, error) {
var e optType var e optType
err := e.FromString(s) err := e.FromString(s)
@ -2176,6 +2242,8 @@ func (e *stockType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
return nil return nil
} }
// NewStockType returns returns an 'enum' value of type stockType given its
// string representation
func NewStockType(s string) (stockType, error) { func NewStockType(s string) (stockType, error) {
var e stockType var e stockType
err := e.FromString(s) err := e.FromString(s)
@ -2238,6 +2306,8 @@ func (e *ofxSec) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
return nil return nil
} }
// NewOfxSec returns returns an 'enum' value of type ofxSec given its
// string representation
func NewOfxSec(s string) (ofxSec, error) { func NewOfxSec(s string) (ofxSec, error) {
var e ofxSec var e ofxSec
err := e.FromString(s) err := e.FromString(s)
@ -2303,6 +2373,8 @@ func (e *holderType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error
return nil return nil
} }
// NewHolderType returns returns an 'enum' value of type holderType given its
// string representation
func NewHolderType(s string) (holderType, error) { func NewHolderType(s string) (holderType, error) {
var e holderType var e holderType
err := e.FromString(s) err := e.FromString(s)
@ -2367,6 +2439,8 @@ func (e *acctClassification) MarshalXML(enc *xml.Encoder, start xml.StartElement
return nil return nil
} }
// NewAcctClassification returns returns an 'enum' value of type acctClassification given its
// string representation
func NewAcctClassification(s string) (acctClassification, error) { func NewAcctClassification(s string) (acctClassification, error) {
var e acctClassification var e acctClassification
err := e.FromString(s) err := e.FromString(s)
@ -2430,6 +2504,8 @@ func (e *svcStatus) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
return nil return nil
} }
// NewSvcStatus returns returns an 'enum' value of type svcStatus given its
// string representation
func NewSvcStatus(s string) (svcStatus, error) { func NewSvcStatus(s string) (svcStatus, error) {
var e svcStatus var e svcStatus
err := e.FromString(s) err := e.FromString(s)
@ -2501,6 +2577,8 @@ func (e *usProductType) MarshalXML(enc *xml.Encoder, start xml.StartElement) err
return nil return nil
} }
// NewUsProductType returns returns an 'enum' value of type usProductType given its
// string representation
func NewUsProductType(s string) (usProductType, error) { func NewUsProductType(s string) (usProductType, error) {
var e usProductType var e usProductType
err := e.FromString(s) err := e.FromString(s)

View File

@ -119,6 +119,8 @@ func (e *{enumLower}) MarshalXML(enc *xml.Encoder, start xml.StartElement) error
return nil return nil
}} }}
// New{enum} returns returns an 'enum' value of type {enumLower} given its
// string representation
func New{enum}(s string) ({enumLower}, error) {{ func New{enum}(s string) ({enumLower}, error) {{
var e {enumLower} var e {enumLower}
err := e.FromString(s) err := e.FromString(s)