(w http.ResponseWriter, r *http.Request)
| 230 | } |
| 231 | |
| 232 | func (a *inboundAPI) handleHostRoutes(w http.ResponseWriter, r *http.Request) { |
| 233 | id := strings.TrimPrefix(r.URL.Path, "/v1/hosts/") |
| 234 | if id == "" { |
| 235 | writeJSON(w, http.StatusNotFound, map[string]any{"error": "host id is required"}) |
| 236 | return |
| 237 | } |
| 238 | switch r.Method { |
| 239 | case http.MethodGet: |
| 240 | item, err := a.store.GetHost(id) |
| 241 | if err != nil { |
| 242 | writeHostError(w, err) |
| 243 | return |
| 244 | } |
| 245 | writeJSON(w, http.StatusOK, item) |
| 246 | case http.MethodPut: |
| 247 | existing, err := a.store.GetHost(id) |
| 248 | if err != nil { |
| 249 | writeHostError(w, err) |
| 250 | return |
| 251 | } |
| 252 | if err := json.NewDecoder(r.Body).Decode(&existing); err != nil { |
| 253 | writeJSON(w, http.StatusBadRequest, map[string]any{"error": "invalid json body"}) |
| 254 | return |
| 255 | } |
| 256 | existing.ID = id |
| 257 | trimHost(&existing) |
| 258 | item, err := a.store.UpsertHost(existing) |
| 259 | if err != nil { |
| 260 | internalError(w, r, err) |
| 261 | return |
| 262 | } |
| 263 | a.triggerHostNodeSync(item) |
| 264 | writeJSON(w, http.StatusOK, item) |
| 265 | case http.MethodDelete: |
| 266 | if err := a.store.DeleteHost(id); err != nil { |
| 267 | writeHostError(w, err) |
| 268 | return |
| 269 | } |
| 270 | writeJSON(w, http.StatusOK, map[string]any{"deleted": true}) |
| 271 | default: |
| 272 | writeMethodNotAllowed(w, http.MethodGet+", "+http.MethodPut+", "+http.MethodDelete) |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | // applyInboundNode 在后台异步将指定节点的最新配置下发到节点(inbound 变更后调用)。 |
| 277 | func (a *inboundAPI) applyInboundNode(nodeID string) { |
nothing calls this directly
no test coverage detected