Merge pull request #313 from influxdata/feature/tr-wire-up-mappings

Wire up /mappings endpoint to layouts
pull/316/head
Chris Goller 2016-11-01 17:05:43 -05:00 committed by GitHub
commit 9a64acc898
1 changed files with 19 additions and 9 deletions

View File

@ -13,15 +13,25 @@ type mapping struct {
// GetMappings returns the known mappings of measurements to applications // GetMappings returns the known mappings of measurements to applications
func (h *Service) GetMappings(w http.ResponseWriter, r *http.Request) { func (h *Service) GetMappings(w http.ResponseWriter, r *http.Request) {
cpu := "cpu" ctx := r.Context()
system := "System" layouts, err := h.LayoutStore.All(ctx)
mp := getMappingsResponse{ if err != nil {
Mappings: []mapping{ Error(w, http.StatusInternalServerError, "Error loading layouts")
mapping{
Measurement: cpu,
Name: system,
},
},
} }
mp := getMappingsResponse{
Mappings: []mapping{},
}
seen := make(map[string]bool)
for _, layout := range layouts {
if seen[layout.Measurement+layout.ID] {
continue
}
mp.Mappings = append(mp.Mappings, mapping{layout.Measurement, layout.ID})
seen[layout.Measurement+layout.ID] = true
}
encodeJSON(w, http.StatusOK, mp, h.Logger) encodeJSON(w, http.StatusOK, mp, h.Logger)
} }