MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / handleHostRoutes

Method handleHostRoutes

internal/serverapi/inbounds.go:232–274  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

230}
231
232func (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 变更后调用)。
277func (a *inboundAPI) applyInboundNode(nodeID string) {

Callers

nothing calls this directly

Calls 9

triggerHostNodeSyncMethod · 0.95
writeHostErrorFunction · 0.85
trimHostFunction · 0.85
internalErrorFunction · 0.85
writeMethodNotAllowedFunction · 0.85
writeJSONFunction · 0.70
GetHostMethod · 0.65
UpsertHostMethod · 0.65
DeleteHostMethod · 0.65

Tested by

no test coverage detected