(w http.ResponseWriter, req *http.Request)
| 25 | } |
| 26 | |
| 27 | func (h *ListFieldsHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { |
| 28 | |
| 29 | // find the index to operate on |
| 30 | var indexName string |
| 31 | if h.IndexNameLookup != nil { |
| 32 | indexName = h.IndexNameLookup(req) |
| 33 | } |
| 34 | if indexName == "" { |
| 35 | indexName = h.defaultIndexName |
| 36 | } |
| 37 | index := IndexByName(indexName) |
| 38 | if index == nil { |
| 39 | showError(w, req, fmt.Sprintf("no such index '%s'", indexName), 404) |
| 40 | return |
| 41 | } |
| 42 | |
| 43 | fields, err := index.Fields() |
| 44 | if err != nil { |
| 45 | showError(w, req, fmt.Sprintf("error: %v", err), 500) |
| 46 | return |
| 47 | } |
| 48 | |
| 49 | fieldsResponse := struct { |
| 50 | Fields []string `json:"fields"` |
| 51 | }{ |
| 52 | Fields: fields, |
| 53 | } |
| 54 | |
| 55 | // encode the response |
| 56 | mustEncode(w, fieldsResponse) |
| 57 | } |
nothing calls this directly
no test coverage detected