本文整理汇总了Golang中xenon/operation.Operation.EncodeBodyAsBuffer方法的典型用法代码示例。如果您正苦于以下问题:Golang Operation.EncodeBodyAsBuffer方法的具体用法?Golang Operation.EncodeBodyAsBuffer怎么用?Golang Operation.EncodeBodyAsBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xenon/operation.Operation
的用法示例。
在下文中一共展示了Operation.EncodeBodyAsBuffer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handlePost
// handlePost calls out to the factory service implementation's POST handler,
// if it exists, and waits for completion. If this runs and completes without
// error, the returned body is passed to the start operation for the service
// created by this factory.
func (f *FactoryServiceContext) handlePost(ctx context.Context, op *operation.Operation) {
var err error
var sd *common.ServiceDocument
if h, ok := f.h.(PostHandler); ok {
// Run the factory service's POST handler and wait for completion.
err = op.CreateChild(ctx).Go(ctx, h.HandlePost).Wait()
if err != nil {
op.Fail(err)
return
}
}
doc := f.h.CreateDocument()
err = op.DecodeBody(doc)
if err != nil && err != io.EOF {
op.Fail(err)
return
}
sd = doc.GetServiceDocument()
sd.SelfLink = path.Join(f.SelfLink(), uuid.New())
op.SetBody(doc)
buf, err := op.EncodeBodyAsBuffer()
if err != nil {
op.Fail(err)
return
}
// Start child service at service document's selflink
startOp := op.NewPost(ctx, uri.Extend(uri.Local(), sd.SelfLink), buf)
f.Host().StartService(startOp, f.h.CreateService())
err = startOp.Wait()
if err != nil {
op.Fail(err)
return
}
op.Complete()
}