platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
55
selective-vpn-api/app/transport_handlers_clients.go
Normal file
55
selective-vpn-api/app/transport_handlers_clients.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func handleTransportClients(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
handleTransportClientsGet(w, r)
|
||||
case http.MethodPost:
|
||||
handleTransportClientsPost(w, r)
|
||||
default:
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
|
||||
func handleTransportClientByID(w http.ResponseWriter, r *http.Request) {
|
||||
const prefix = "/api/v1/transport/clients/"
|
||||
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 == "" {
|
||||
http.Error(w, "invalid client id", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if len(parts) == 1 {
|
||||
handleTransportClientCard(w, r, id)
|
||||
return
|
||||
}
|
||||
handleTransportClientAction(w, r, id, strings.ToLower(strings.TrimSpace(parts[1])))
|
||||
}
|
||||
|
||||
func handleTransportClientCard(w http.ResponseWriter, r *http.Request, id string) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
handleTransportClientCardGet(w, r, id)
|
||||
case http.MethodPatch:
|
||||
handleTransportClientCardPatch(w, r, id)
|
||||
case http.MethodDelete:
|
||||
handleTransportClientCardDelete(w, r, id)
|
||||
default:
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user