f-21: add first api file

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-04-12 17:29:37 +02:00
commit bcedeece18
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
5 changed files with 104 additions and 0 deletions

View file

@ -0,0 +1,25 @@
package agentapi
import (
"encoding/json"
"net/http"
"strings"
)
func SubnetByNameHandler(w http.ResponseWriter, r *http.Request) {
name := strings.TrimPrefix(r.URL.Path, "/subnets/")
if name == "" {
http.NotFound(w, r)
return
}
w.Header().Set("Content-Type", "application/json")
switch r.Method {
case http.MethodGet:
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]string{"name": name})
case http.MethodDelete:
w.WriteHeader(http.StatusAccepted)
default:
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
}
}