package app import ( "net/http" "strings" ) func handleTransportSingBoxProfileByID(w http.ResponseWriter, r *http.Request) { const prefix = "/api/v1/transport/singbox/profiles/" rest := strings.TrimPrefix(r.URL.Path, prefix) if rest == "" || rest == r.URL.Path { http.NotFound(w, r) return } parts := strings.Split(strings.Trim(rest, "/"), "/") if len(parts) == 0 || strings.TrimSpace(parts[0]) == "" { http.NotFound(w, r) return } id := sanitizeID(parts[0]) if id == "" { writeJSON(w, http.StatusBadRequest, SingBoxProfilesResponse{ OK: false, Code: singBoxProfileCodeBadID, Message: "invalid profile id", }) return } if len(parts) == 1 { handleTransportSingBoxProfileCard(w, r, id) return } if len(parts) > 2 { http.NotFound(w, r) return } action := strings.ToLower(strings.TrimSpace(parts[1])) handleTransportSingBoxProfileAction(w, r, id, action) } func handleTransportSingBoxProfileCard(w http.ResponseWriter, r *http.Request, id string) { switch r.Method { case http.MethodGet: handleTransportSingBoxProfileCardGet(w, r, id) case http.MethodPatch: handleTransportSingBoxProfileCardPatch(w, r, id) case http.MethodDelete: handleTransportSingBoxProfileCardDelete(w, r, id) default: http.Error(w, "method not allowed", http.StatusMethodNotAllowed) } }