2016-10-25 15:20:06 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import "net/http"
|
|
|
|
|
|
|
|
type getMappingsResponse struct {
|
|
|
|
Mappings []mapping `json:"mappings"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type mapping struct {
|
|
|
|
Measurement string `json:"measurement"` // The measurement where data for this mapping is found
|
|
|
|
Name string `json:"name"` // The application name which will be assigned to the corresponding measurement
|
|
|
|
}
|
|
|
|
|
2016-10-28 16:27:06 +00:00
|
|
|
// GetMappings returns the known mappings of measurements to applications
|
|
|
|
func (h *Service) GetMappings(w http.ResponseWriter, r *http.Request) {
|
2016-11-01 19:49:10 +00:00
|
|
|
ctx := r.Context()
|
|
|
|
layouts, err := h.LayoutStore.All(ctx)
|
|
|
|
if err != nil {
|
2016-11-19 17:41:06 +00:00
|
|
|
Error(w, http.StatusInternalServerError, "Error loading layouts", h.Logger)
|
2016-11-11 18:52:34 +00:00
|
|
|
return
|
2016-11-01 19:49:10 +00:00
|
|
|
}
|
|
|
|
|
2016-10-25 15:20:06 +00:00
|
|
|
mp := getMappingsResponse{
|
2016-11-01 19:49:10 +00:00
|
|
|
Mappings: []mapping{},
|
|
|
|
}
|
|
|
|
|
|
|
|
seen := make(map[string]bool)
|
|
|
|
|
|
|
|
for _, layout := range layouts {
|
|
|
|
if seen[layout.Measurement+layout.ID] {
|
|
|
|
continue
|
|
|
|
}
|
2016-11-04 18:04:50 +00:00
|
|
|
mp.Mappings = append(mp.Mappings, mapping{layout.Measurement, layout.Application})
|
2016-11-01 19:49:10 +00:00
|
|
|
seen[layout.Measurement+layout.ID] = true
|
2016-10-25 15:20:06 +00:00
|
|
|
}
|
2016-11-01 19:49:10 +00:00
|
|
|
|
2016-10-25 15:20:06 +00:00
|
|
|
encodeJSON(w, http.StatusOK, mp, h.Logger)
|
|
|
|
}
|