GetListKeysHandler 支持http获取数据库中所有键
(w http.ResponseWriter, r *http.Request)
| 130 | |
| 131 | // GetListKeysHandler 支持http获取数据库中所有键 |
| 132 | func (hs *HttpHandler) GetListKeysHandler(w http.ResponseWriter, r *http.Request) { |
| 133 | keys := hs.GetListKeys() |
| 134 | if keys == nil { |
| 135 | http.Error(w, "key is empty", http.StatusBadRequest) |
| 136 | return |
| 137 | } |
| 138 | jsonKeys, err := json.Marshal(keys) |
| 139 | if err != nil { |
| 140 | // Handle the error |
| 141 | http.Error(w, "Internal Server Error", http.StatusInternalServerError) |
| 142 | return |
| 143 | } |
| 144 | |
| 145 | // Write the JSON response |
| 146 | _, err = w.Write(jsonKeys) |
| 147 | if err != nil { |
| 148 | // 处理写入响应失败的错误 |
| 149 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 150 | return |
| 151 | } |
| 152 | } |
nothing calls this directly
no test coverage detected