예제 #1
0
func (r *router) executors(
	ctx types.Context,
	w http.ResponseWriter,
	req *http.Request,
	store types.Store) error {

	var reply types.ExecutorsMap = map[string]*types.ExecutorInfo{}
	for ei := range executors.ExecutorInfos() {
		reply[ei.Name] = &ei.ExecutorInfo
	}

	return httputils.WriteJSON(w, http.StatusOK, reply)
}
예제 #2
0
func (r *router) serviceInspect(
	ctx types.Context,
	w http.ResponseWriter,
	req *http.Request,
	store types.Store) error {

	service := context.MustService(ctx)
	si, err := toServiceInfo(ctx, service, store)
	if err != nil {
		return err
	}
	httputils.WriteJSON(w, http.StatusOK, si)
	return nil
}
예제 #3
0
// Handle is the type's Handler function.
func (h *errorHandler) Handle(
	ctx types.Context,
	w http.ResponseWriter,
	req *http.Request,
	store types.Store) error {

	err := h.handler(ctx, w, req, store)
	if err == nil {
		return nil
	}

	ctx.Error(err)

	httpErr := goof.NewHTTPError(err, getStatus(err))
	httputils.WriteJSON(w, httpErr.Status(), httpErr)
	return nil
}
예제 #4
0
func (r *router) servicesList(
	ctx types.Context,
	w http.ResponseWriter,
	req *http.Request,
	store types.Store) error {

	reply := map[string]*types.ServiceInfo{}
	for service := range services.StorageServices(ctx) {
		ctx := context.WithStorageService(ctx, service)
		si, err := toServiceInfo(ctx, service, store)
		if err != nil {
			return err
		}
		reply[si.Name] = si
	}

	httputils.WriteJSON(w, http.StatusOK, reply)
	return nil
}
예제 #5
0
func (r *router) root(
	ctx types.Context,
	w http.ResponseWriter,
	req *http.Request,
	store types.Store) error {

	proto := "http"
	if req.TLS != nil {
		proto = "https"
	}
	rootURL := fmt.Sprintf("%s://%s", proto, req.Host)

	reply := []string{
		fmt.Sprintf("%s/executors", rootURL),
		fmt.Sprintf("%s/services", rootURL),
		fmt.Sprintf("%s/snapshots", rootURL),
		fmt.Sprintf("%s/tasks", rootURL),
		fmt.Sprintf("%s/help", rootURL),
		fmt.Sprintf("%s/volumes", rootURL),
	}

	httputils.WriteJSON(w, http.StatusOK, reply)
	return nil
}