本文整理汇总了Golang中github.com/willfaught/company/prototype/company/offer.Offer.Created方法的典型用法代码示例。如果您正苦于以下问题:Golang Offer.Created方法的具体用法?Golang Offer.Created怎么用?Golang Offer.Created使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/willfaught/company/prototype/company/offer.Offer
的用法示例。
在下文中一共展示了Offer.Created方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: New
// New creates o.
func (os Offers) New(o offer.Offer) (offer.Offer, error) {
o.ID = tigertonic.RandomBase62String(8)
o.Created = time.Now().UTC()
o.Deleted = time.Time{}
o.Updated = time.Time{}
if err := o.Validate(); err != nil {
return offer.Offer{}, err
}
os.Configuration.OfferRepository.Store(o)
return o, nil
}
示例2: Set
// Set updates o.
func (os Offers) Set(o offer.Offer) (offer.Offer, error) {
var old, ok = os.Configuration.OfferRepository.Load(o.ID)
if !ok {
return offer.Offer{}, fmt.Errorf("invalid id: %q", o.ID)
}
if !old.Deleted.IsZero() {
return offer.Offer{}, fmt.Errorf("invalid id: %q", o.ID)
}
o.Created = old.Created
o.Deleted = old.Deleted
o.Updated = time.Now().UTC()
if err := o.Validate(); err != nil {
return offer.Offer{}, err
}
os.Configuration.OfferRepository.Store(o)
return o, nil
}