本文整理汇总了Golang中github.com/willfaught/company/prototype/company/offer.Offer类的典型用法代码示例。如果您正苦于以下问题:Golang Offer类的具体用法?Golang Offer怎么用?Golang Offer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Offer类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
}
开发者ID:willfaught,项目名称:services,代码行数:18,代码来源:offers.go
示例2: Delete
// Delete deletes o.
func (os Offers) Delete(o offer.Offer) (offer.Offer, error) {
o, ok := os.Configuration.OfferRepository.Load(o.ID)
if !ok {
return offer.Offer{}, fmt.Errorf("invalid id: %q", o.ID)
}
if !o.Deleted.IsZero() {
return offer.Offer{}, fmt.Errorf("invalid id: %q", o.ID)
}
o.Deleted = time.Now().UTC()
os.Configuration.OfferRepository.Store(o)
return o, nil
}
开发者ID:willfaught,项目名称:services,代码行数:13,代码来源:offers.go
示例3: ExampleMethod
// ExampleMethod shows using a method.
func ExampleMethod() {
log.Println("\n***** ExampleMethod *****\n")
// Server
var server = offers.MustNewServer(configure("Server"), offers.Offers{Configuration: configure("Server")}, ":4020")
go func() {
if err := server.Start(); err != nil {
panic(err)
}
}()
// Client
var client = offers.MustNewClient(configure("Client"), ":4020").ForContext(offers.Context{ID: tigertonic.RandomBase62String(8)}).(offers.Client)
// Use
var m = offer.Offer{Interface: client, Name: "nerddomo"}
m, err := m.New()
if err != nil {
panic(err)
}
log.Printf("New: Got: %# v\n\n", pretty.Formatter(simplify(m)))
m, err = client.Get(m.ID)
if err != nil {
panic(err)
}
log.Printf("Get: Got: %# v\n\n", pretty.Formatter(simplify(m)))
m.Name = "bar"
m, err = m.Set()
if err != nil {
panic(err)
}
log.Printf("Set: Got: %# v\n\n", pretty.Formatter(simplify(m)))
m, err = m.Delete()
if err != nil {
panic(err)
}
log.Printf("Delete: Got: %# v\n\n", pretty.Formatter(simplify(m)))
// Client
if err := client.Close(); err != nil {
panic(err)
}
// Server
if err := server.Stop(); err != nil {
panic(err)
}
}
开发者ID:willfaught,项目名称:services,代码行数:49,代码来源:main.go
示例4: 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
}
开发者ID:willfaught,项目名称:services,代码行数:12,代码来源:offers.go
示例5: New
// New creates m.
func (c Client) New(m offer.Offer) (offer.Offer, error) {
m.Interface = nil
var argument = struct {
Arguments struct {
M offer.Offer
}
Context Context
}{
Arguments: struct {
M offer.Offer
}{
M: m,
},
Context: c.Context,
}
var result struct {
Offer offer.Offer
}
c.Configuration.OnCall("New", argument.Context, argument.Arguments)
var err = c.Client.Call(c.Name+".New", argument, &result)
c.Configuration.OnReturn("New", argument.Context, result, err)
result.Offer.Interface = c
return result.Offer, err
}
开发者ID:willfaught,项目名称:services,代码行数:25,代码来源:client.go
示例6: Delete
// Delete deletes m.
func (c Client) Delete(m offer.Offer) (offer.Offer, error) {
m.Interface = nil // Avoid encoding the Service or Client
var argument = struct {
Arguments struct { // Method arguments
M offer.Offer // m
}
Context Context // Call context
}{
Arguments: struct { // Method arguments
M offer.Offer // m
}{
M: m, // m
},
Context: c.Context, // Call context
}
var result struct { // Method result
Offer offer.Offer // Only one non-error result
}
c.Configuration.OnCall("Delete", argument.Context, argument.Arguments) // Called because Configuration implements it
var err = c.Client.Call(c.Name+".Delete", argument, &result)
c.Configuration.OnReturn("Delete", argument.Context, result, err) // Called because Configuration implements it
result.Offer.Interface = c // Enable method calls like m.Delete(). See offer.Offer.Delete.
return result.Offer, err
}
开发者ID:willfaught,项目名称:services,代码行数:25,代码来源:client.go
示例7: ExampleGracefulRestart
// ExampleGracefulRestart shows enabling graceful restarts.
func ExampleGracefulRestart() {
log.Println("\n***** ExampleGracefulRestart *****\n")
// Server
var gn = &gracenet.Net{}
var listener, err = gn.Listen("tcp", ":4545")
if err != nil {
panic(err)
}
var server = offers.Server{Listener: listener, Server: rpc.NewServer()}
server.RegisterName("Marketing", offers.Receiver{Configuration: configure("Server"), Interface: offers.Offers{Configuration: configure("Server")}})
go func() {
if err := server.Start(); err != nil {
panic(err)
}
}()
var done = make(chan struct{})
go func() {
var c = make(chan os.Signal, 10)
signal.Notify(c, syscall.SIGTERM, syscall.SIGUSR2)
for {
var s = <-c
switch s {
case syscall.SIGTERM:
log.Println("Received SIGTERM\n")
signal.Stop(c)
done <- struct{}{}
return
case syscall.SIGUSR2:
log.Println("Received SIGUSR2\n")
if _, err := gn.StartProcess(); err != nil {
log.Fatalln("Error:", err)
}
}
}
}()
// Client
var client = offers.MustNewClient(configure("Client"), ":4545").ForContext(offers.Context{ID: tigertonic.RandomBase62String(8)}).(offers.Client)
// Use
Main:
for {
var m = offer.Offer{Interface: client, Name: "nerddomo"}
m, err := m.New()
if err != nil {
panic(err)
}
log.Printf("New: Got: %# v\n\n", pretty.Formatter(simplify(m)))
m, err = client.Get(m.ID)
if err != nil {
panic(err)
}
log.Printf("Get: Got: %# v\n\n", pretty.Formatter(simplify(m)))
m.Name = "bar"
m, err = m.Set()
if err != nil {
panic(err)
}
log.Printf("Set: Got: %# v\n\n", pretty.Formatter(simplify(m)))
m, err = m.Delete()
if err != nil {
panic(err)
}
log.Printf("Delete: Got: %# v\n\n", pretty.Formatter(simplify(m)))
log.Println()
select {
case <-done:
break Main
case <-time.After(time.Second * 10):
}
}
// Client
if err := client.Close(); err != nil {
panic(err)
}
// Server
if err := server.Stop(); err != nil {
panic(err)
}
}
开发者ID:willfaught,项目名称:services,代码行数:84,代码来源:main.go
示例8: simplify
func simplify(o offer.Offer) offer.Offer {
o.Interface = nil
return o
}
开发者ID:willfaught,项目名称:services,代码行数:4,代码来源:main.go
注:本文中的github.com/willfaught/company/prototype/company/offer.Offer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论