示例#1
0
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
}
示例#2
0
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)
}
示例#3
0
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)
}