57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package app
|
|
|
|
import (
|
|
"net/http"
|
|
trafficcandidatespkg "selective-vpn-api/app/trafficcandidates"
|
|
"time"
|
|
)
|
|
|
|
func handleTrafficCandidates(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodGet {
|
|
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
|
return
|
|
}
|
|
|
|
payload := trafficcandidatespkg.Collect(
|
|
time.Now().UTC(),
|
|
trafficcandidatespkg.Deps{
|
|
RunCommand: runCommand,
|
|
ParseRouteDevice: parseRouteDevice,
|
|
IsVPNLikeIface: isVPNLikeIface,
|
|
IsContainerIface: isContainerIface,
|
|
IsAutoBypassDestination: isAutoBypassDestination,
|
|
},
|
|
)
|
|
|
|
resp := TrafficCandidatesResponse{
|
|
GeneratedAt: payload.GeneratedAt,
|
|
Subnets: make([]TrafficCandidateSubnet, 0, len(payload.Subnets)),
|
|
Units: make([]TrafficCandidateUnit, 0, len(payload.Units)),
|
|
UIDs: make([]TrafficCandidateUID, 0, len(payload.UIDs)),
|
|
}
|
|
for _, it := range payload.Subnets {
|
|
resp.Subnets = append(resp.Subnets, TrafficCandidateSubnet{
|
|
CIDR: it.CIDR,
|
|
Dev: it.Dev,
|
|
Kind: it.Kind,
|
|
LinkDown: it.LinkDown,
|
|
})
|
|
}
|
|
for _, it := range payload.Units {
|
|
resp.Units = append(resp.Units, TrafficCandidateUnit{
|
|
Unit: it.Unit,
|
|
Description: it.Description,
|
|
Cgroup: it.Cgroup,
|
|
})
|
|
}
|
|
for _, it := range payload.UIDs {
|
|
resp.UIDs = append(resp.UIDs, TrafficCandidateUID{
|
|
UID: it.UID,
|
|
User: it.User,
|
|
Examples: it.Examples,
|
|
})
|
|
}
|
|
|
|
writeJSON(w, http.StatusOK, resp)
|
|
}
|