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

Method handleUser

internal/serverapi/users.go:213–244  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request, userID string)

Source from the content-addressed store, hash-verified

211}
212
213func (a *userAPI) handleUser(w http.ResponseWriter, r *http.Request, userID string) {
214 switch r.Method {
215 case http.MethodGet:
216 user, err := a.users.GetUser(userID)
217 if err != nil {
218 writeUserError(w, err)
219 return
220 }
221 writeJSON(w, http.StatusOK, user)
222 case http.MethodPut:
223 a.handleUpdateUser(w, r, userID)
224 case http.MethodDelete:
225 // 删除前先收集该用户所在的节点,删除后重新下发配置以踢出用户
226 accesses, _ := a.users.ListUserInboundsByUser(userID)
227 affectedNodeIDs := make(map[string]struct{})
228 for _, acc := range accesses {
229 affectedNodeIDs[acc.NodeID] = struct{}{}
230 }
231 if err := a.users.DeleteUser(userID); err != nil {
232 writeUserError(w, err)
233 return
234 }
235 nodeIDs := make([]string, 0, len(affectedNodeIDs))
236 for id := range affectedNodeIDs {
237 nodeIDs = append(nodeIDs, id)
238 }
239 a.applyNodes(nodeIDs)
240 writeJSON(w, http.StatusOK, map[string]any{"deleted": true})
241 default:
242 writeMethodNotAllowed(w, http.MethodGet+", "+http.MethodPut+", "+http.MethodDelete)
243 }
244}
245
246func (a *userAPI) handleUpdateUser(w http.ResponseWriter, r *http.Request, userID string) {
247 user, err := a.users.GetUser(userID)

Callers 1

handleUserRoutesMethod · 0.95

Calls 8

handleUpdateUserMethod · 0.95
applyNodesMethod · 0.95
writeUserErrorFunction · 0.85
writeMethodNotAllowedFunction · 0.85
writeJSONFunction · 0.70
GetUserMethod · 0.65
DeleteUserMethod · 0.65

Tested by

no test coverage detected