From ae5afea4be8ca56e3fb7963fea5e337332e50a1f Mon Sep 17 00:00:00 2001 From: bnewbold Date: Tue, 17 Apr 2012 23:15:34 -0400 Subject: basic dumping in several formats --- core.go | 55 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 22 deletions(-) (limited to 'core.go') diff --git a/core.go b/core.go index 5d76f71..087a3f4 100644 --- a/core.go +++ b/core.go @@ -5,44 +5,55 @@ import ( ) type OfferPrice struct { - Currency string - MinQty uint32 - Price float32 + Currency string `json:"currency"` + MinQty uint32 `json:"min_qty"` + Price float32 `json:"price"` } type Offer struct { - Distributor, Sku, Url, Comment string - Prices []OfferPrice + Distributor string `json:"distributor_name"` + Sku string `json:"sku"` + Url string `json:"distributor_url"` + Comment string `json:"comment"` + Prices []OfferPrice `json:"prices"` } type LineItem struct { - Mfg, Mpn, Description, Comment, Tag string - Elements []string // TODO: add "circuit element" type - Offers []Offer + Manufacturer string `json:"manufacturer"` + Mpn string `json:"mpn"` + Description string `json:"description"` + Comment string `json:"comment"` + Tag string `json:"tag"` + // TODO: add "circuit element" type? + Elements []string `json:"elements"` + Offers []Offer `json:"offers"` } func (li *LineItem) Id() string { - return li.Mfg + "::" + li.Mpn + return li.Manufacturer + "::" + li.Mpn } // The main anchor of a BOM as a cohesive whole, with a name and permissions. // Multiple BOMs are associated with a single BomStub; the currently active one // is the 'head'. type BomStub struct { - Name string - Owner string - Description string - HeadVersion string - Homepage *Url - IsPublicView, IsPublicEdit bool + Name string `json:"name"` + Owner string `json:"owner_name"` + Description string `json:"description"` + HeadVersion string `json:"head_version"` + Homepage *Url `json:"homepage_url"` + IsPublicView bool `json:"is_publicview",omitempty` + IsPublicEdit bool `json:"is_publicedit",omitempty` } // An actual list of parts/elements. Intended to be immutable once persisted. type Bom struct { - Version string - Created time.Time // TODO: unix timestamp? - Progeny string // where did this BOM come from? - LineItems []LineItem + Version string `json:"version"` + // TODO: unix timestamp? + Created time.Time `json:"created_ts"` + // "where did this BOM come from?" + Progeny string `json:"progeny",omitifempty` + LineItems []LineItem `json:"line_items"` } func NewBom(version string) *Bom { @@ -51,7 +62,7 @@ func NewBom(version string) *Bom { func (b *Bom) GetLineItem(mfg, mpn string) *LineItem { for _, li := range b.LineItems { - if li.Mfg == mfg && li.Mpn == mpn { + if li.Manufacturer == mfg && li.Mpn == mpn { return &li } } @@ -59,7 +70,7 @@ func (b *Bom) GetLineItem(mfg, mpn string) *LineItem { } func (b *Bom) AddLineItem(li *LineItem) error { - if eli := b.GetLineItem(li.Mfg, li.Mpn); eli != nil { + if eli := b.GetLineItem(li.Manufacturer, li.Mpn); eli != nil { return Error("This BOM already had an identical LineItem") } b.LineItems = append(b.LineItems, *li) @@ -73,7 +84,7 @@ func makeTestBom() *Bom { o := Offer{Sku: "A123", Distributor: "Acme", Prices: []OfferPrice{op1, op2}} //o.AddOfferPrice(op1) //o.AddOfferPrice(op2) - li := LineItem{Mfg: "WidgetCo", + li := LineItem{Manufacturer: "WidgetCo", Mpn: "WIDG0001", Elements: []string{"W1", "W2"}, Offers: []Offer{o}} -- cgit v1.2.3