• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang operation.Operation类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中xenon/operation.Operation的典型用法代码示例。如果您正苦于以下问题:Golang Operation类的具体用法?Golang Operation怎么用?Golang Operation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Operation类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: HandleRequest

func (s *ServiceContext) HandleRequest(ctx context.Context, op *operation.Operation) {
	switch op.GetRequest().Method {
	case "GET":
		if s.hGet != nil {
			s.hGet(ctx, op)
			return
		}
	case "POST":
		if s.hPost != nil {
			s.hPost(ctx, op)
			return
		}
	case "PATCH":
		if s.hPatch != nil {
			s.hPatch(ctx, op)
			return
		}
	case "PUT":
		if s.hPut != nil {
			s.hPut(ctx, op)
			return
		}
	case "DELETE":
		if s.hDelete != nil {
			s.hDelete(ctx, op)
			return
		}
	}

	op.Fail(errors.MethodNotAllowed{Allowed: s.allowedMethods()})
	return
}
开发者ID:vmware,项目名称:xenon,代码行数:32,代码来源:service_context.go


示例2: HandleGet

// Return the QueryResult to simulate factory get behavior
func (s *MockFactoryService) HandleGet(ctx context.Context, op *operation.Operation) {
	type factoryQueryResult struct {
		common.ServiceDocumentQueryResult
		Documents map[string]interface{} `json:"documents,omitempty"`
	}
	result := factoryQueryResult{}
	result.Documents = s.ServiceMap
	op.SetBody(result).Complete()
}
开发者ID:vmware,项目名称:xenon,代码行数:10,代码来源:mock_factory_service.go


示例3: HandleRequest

func (f *FactoryServiceContext) HandleRequest(ctx context.Context, op *operation.Operation) {
	// TODO(PN): Support GET (need a way to get elements) and DELETE
	switch op.GetRequest().Method {
	case "POST":
	default:
		err := errors.MethodNotAllowed{Allowed: []string{"POST"}}
		op.Fail(err)
		return
	}

	f.handlePost(ctx, op)
}
开发者ID:vmware,项目名称:xenon,代码行数:12,代码来源:factory_service_context.go


示例4: HandleStart

func (s *ServiceContext) HandleStart(ctx context.Context, op *operation.Operation) {
	err := op.DecodeBody(s.h.GetState())
	if err != nil && err != operation.ErrBodyNotSet {
		op.Fail(err)
		return
	}

	// Run the service handler's start handler if available
	if h, ok := s.h.(StartHandler); ok {
		err = op.CreateChild(ctx).Go(ctx, h.HandleStart).Wait()
		if err != nil {
			op.Fail(err)
			return
		}
	}

	op.Complete()
}
开发者ID:vmware,项目名称:xenon,代码行数:18,代码来源:service_context.go


示例5: HandlePost

func (s *MockFactoryService) HandlePost(ctx context.Context, op *operation.Operation) {
	state := s.createStatef()
	op.DecodeBody(&state)

	val := reflect.ValueOf(state).Elem()
	f := val.FieldByName("SelfLink")
	var selfLink string
	if f.Kind() == reflect.String && f.Len() > 0 {
		selfLink = f.String()
	}

	if len(selfLink) == 0 {
		selfLink = s.factoryURI + "/" + uuid.New()
		if f.Len() == 0 {
			f.SetString(selfLink)
		}
	}
	_ = s.th.StartMockWithSelfLink(state, selfLink)
	s.ServiceMap[selfLink] = state
	op.SetBody(state).Complete()
}
开发者ID:vmware,项目名称:xenon,代码行数:21,代码来源:mock_factory_service.go


示例6: StartService

// StartService starts the specified service. The operation parameter is used
// for the context of the start; the service's URI, the referrer, signaling
// completion of the service start, etc.
//
// Upon returning, either the operation has failed, or the service is still
// going through the motions of being started. In the latter case, the caller
// can wait for completion of the operation to ensure the service is fully
// started.
//
func (h *ServiceHost) StartService(op *operation.Operation, s Service) {
	s.SetHost(h)

	// The selflink is expected to be either set on the service externally
	// (before starting the service), or as the URI path on the operation.
	selfLink := s.SelfLink()
	if selfLink == "" {
		// Prefix path with / to make sure it is absolute.
		// The clean function removes double /'s and the trailing /, if any.
		selfLink = path.Clean("/" + op.GetURI().Path)
		s.SetSelfLink(selfLink)
	}

	// Add service to the host's service map.
	h.Lock()
	_, ok := h.services[selfLink]
	if ok {
		h.Unlock()
		op.Fail(errors.New("host: service is already bound"))
		return
	}
	h.services[selfLink] = s
	h.Unlock()

	// Service is now attached to host; move to initialized state.
	if err := s.SetStage(StageInitialized); err != nil {
		op.Fail(err)
		return
	}

	// Start service asynchronously.
	go h.startService(op, s)
}
开发者ID:vmware,项目名称:xenon,代码行数:42,代码来源:service_host.go


示例7: HandleRequest

func (h *ServiceHost) HandleRequest(ctx context.Context, op *operation.Operation) {
	selfLink := path.Clean(op.GetRequest().URL.Path)

	h.RLock()
	s, ok := h.services[selfLink]
	h.RUnlock()

	if !ok {
		// TODO(PN): Check if the path points to a utility service
		op.SetStatusCode(http.StatusNotFound).Complete()
		return
	}

	// Queue request if service is not yet available
	if s.Stage() < StageAvailable {
		select {
		case <-op.Done():
			return // Operation is already done, no need to complete.
		case <-s.StageBarrier(StageAvailable):
			// Continue
		}
	}

	s.HandleRequest(ctx, op)
}
开发者ID:vmware,项目名称:xenon,代码行数:25,代码来源:service_host.go


示例8: startService

// startService executes the necessary actions to move a service from
// the available stage, to the started stage, to the available stage.
func (h *ServiceHost) startService(op *operation.Operation, s Service) {
	ctx := context.Background()
	err := op.CreateChild(ctx).Go(ctx, s.HandleStart).Wait()
	if err != nil {
		op.Fail(err)
		return
	}

	if err := s.SetStage(StageStarted); err != nil {
		op.Fail(err)
		return
	}

	// Stuff may happen between the started and available stages.
	// This separation is kept here for parity with the Java XENON implementation.

	if err := s.SetStage(StageAvailable); err != nil {
		op.Fail(err)
		return
	}

	op.Complete()
}
开发者ID:vmware,项目名称:xenon,代码行数:25,代码来源:service_host.go


示例9: HandlePatch

func (s *pingService) HandlePatch(ctx context.Context, op *operation.Operation) {
	req := &pingRequest{}
	err := op.DecodeBody(req)
	if err != nil {
		op.Fail(err)
		return
	}

	op.SetStatusCode(http.StatusCreated)
	op.Complete()

	// Ping specified URL
	pingOp := operation.NewPatch(ctx, req.URI, nil)
	pingOp.SetBody(req)
	client.Send(pingOp)
}
开发者ID:vmware,项目名称:xenon,代码行数:16,代码来源:ping_service.go


示例10: HandleGet

func (s *ServiceContext) HandleGet(ctx context.Context, op *operation.Operation) {
	op.SetBody(s.h.GetState()).Complete()
}
开发者ID:vmware,项目名称:xenon,代码行数:3,代码来源:service_context.go


示例11: HandleRequest

func (m *MinimalService) HandleRequest(ctx context.Context, op *operation.Operation) {
	op.Fail(errors.New("host: service not implemented"))
}
开发者ID:vmware,项目名称:xenon,代码行数:3,代码来源:minimal_service.go


示例12: HandleStart

func (m *MinimalService) HandleStart(ctx context.Context, op *operation.Operation) {
	op.Complete()
}
开发者ID:vmware,项目名称:xenon,代码行数:3,代码来源:minimal_service.go


示例13: 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()
}
开发者ID:vmware,项目名称:xenon,代码行数:45,代码来源:factory_service_context.go


示例14: HandleStart

func (f *FactoryServiceContext) HandleStart(ctx context.Context, op *operation.Operation) {
	op.Complete()
}
开发者ID:vmware,项目名称:xenon,代码行数:3,代码来源:factory_service_context.go



注:本文中的xenon/operation.Operation类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang xml.Unmarshal函数代码示例发布时间:2022-05-28
下一篇:
Golang module_state2.State类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap