From 277ee1e25e8ef02163bc1bd9d4d2f665512e71c6 Mon Sep 17 00:00:00 2001 From: Todd Gruben Date: Mon, 18 Jun 2018 13:28:24 -0500 Subject: [PATCH 1/3] added fields meta to index http endpoint --- http/handler.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/http/handler.go b/http/handler.go index df5108826..1d43fea5d 100644 --- a/http/handler.go +++ b/http/handler.go @@ -343,16 +343,22 @@ func (h *Handler) handleGetIndex(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), http.StatusNotFound) return } + fields := make(map[string]string) + for _, field := range index.Fields() { + fields["name"] = field.Name() + } if err := json.NewEncoder(w).Encode(getIndexResponse{ - map[string]string{"name": index.Name()}, + Index: map[string]string{"name": index.Name()}, + Fields: fields, }); err != nil { h.Logger.Printf("write response error: %s", err) } } type getIndexResponse struct { - Index map[string]string `json:"index"` + Index map[string]string `json:"index"` + Fields map[string]string `json:"fields"` } type postIndexRequest struct { From 07ab60d6cf76f3e77aa7a206996b57b6c478ef03 Mon Sep 17 00:00:00 2001 From: Todd Gruben Date: Mon, 18 Jun 2018 13:58:12 -0500 Subject: [PATCH 2/3] adjust requirements to match schema response --- http/handler.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/http/handler.go b/http/handler.go index 1d43fea5d..c509971a2 100644 --- a/http/handler.go +++ b/http/handler.go @@ -337,29 +337,31 @@ func (h *Handler) handleGetIndexes(w http.ResponseWriter, r *http.Request) { // handleGetIndex handles GET /index/ requests. func (h *Handler) handleGetIndex(w http.ResponseWriter, r *http.Request) { + indexName := mux.Vars(r)["index"] - index, err := h.API.Index(r.Context(), indexName) - if err != nil { - http.Error(w, err.Error(), http.StatusNotFound) + var info *pilosa.IndexInfo + for _, idx := range h.API.Schema(r.Context()) { + if strings.Compare(idx.Name, indexName) == 0 { + info = idx + break + } + } + if info == nil { + http.Error(w, fmt.Sprintf("Index %s Not Found", indexName), http.StatusNotFound) return } - fields := make(map[string]string) - for _, field := range index.Fields() { - fields["name"] = field.Name() - } - if err := json.NewEncoder(w).Encode(getIndexResponse{ - Index: map[string]string{"name": index.Name()}, - Fields: fields, - }); err != nil { + if err := json.NewEncoder(w).Encode(info); err != nil { h.Logger.Printf("write response error: %s", err) } } +/* type getIndexResponse struct { Index map[string]string `json:"index"` Fields map[string]string `json:"fields"` } +*/ type postIndexRequest struct { Options pilosa.IndexOptions `json:"options"` From 18c67269ae794490653604b298a1f1fcd8812a39 Mon Sep 17 00:00:00 2001 From: Todd Gruben Date: Mon, 18 Jun 2018 14:08:22 -0500 Subject: [PATCH 3/3] clarity --- http/handler.go | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/http/handler.go b/http/handler.go index c509971a2..9aea6e12c 100644 --- a/http/handler.go +++ b/http/handler.go @@ -337,32 +337,18 @@ func (h *Handler) handleGetIndexes(w http.ResponseWriter, r *http.Request) { // handleGetIndex handles GET /index/ requests. func (h *Handler) handleGetIndex(w http.ResponseWriter, r *http.Request) { - indexName := mux.Vars(r)["index"] - var info *pilosa.IndexInfo for _, idx := range h.API.Schema(r.Context()) { - if strings.Compare(idx.Name, indexName) == 0 { - info = idx - break + if idx.Name == indexName { + if err := json.NewEncoder(w).Encode(idx); err != nil { + h.Logger.Printf("write response error: %s", err) + } + return } } - if info == nil { - http.Error(w, fmt.Sprintf("Index %s Not Found", indexName), http.StatusNotFound) - return - } - - if err := json.NewEncoder(w).Encode(info); err != nil { - h.Logger.Printf("write response error: %s", err) - } + http.Error(w, fmt.Sprintf("Index %s Not Found", indexName), http.StatusNotFound) } -/* -type getIndexResponse struct { - Index map[string]string `json:"index"` - Fields map[string]string `json:"fields"` -} -*/ - type postIndexRequest struct { Options pilosa.IndexOptions `json:"options"` }