(w http.ResponseWriter, val interface{}, format string)
| 192 | } |
| 193 | |
| 194 | func formatValue(w http.ResponseWriter, val interface{}, format string) { |
| 195 | w.WriteHeader(200) |
| 196 | w.Header().Add("content-type", "text/plain") |
| 197 | |
| 198 | switch format { |
| 199 | case "json", "json-pretty": |
| 200 | enc := json.NewEncoder(w) |
| 201 | if format == "json-pretty" { |
| 202 | enc.SetIndent("", " ") |
| 203 | } |
| 204 | |
| 205 | err := enc.Encode(val) |
| 206 | if err != nil { |
| 207 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 208 | } |
| 209 | |
| 210 | default: |
| 211 | _, _ = fmt.Fprintf(w, "%#v", val) |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | func downloadKey(w http.ResponseWriter, kv *KV, store map[string]ValueDesc, key string) { |
| 216 | if store[key].value == nil { |
no test coverage detected