Beispiel #1
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)
}
Beispiel #2
0
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)
}