f-21: add first api file
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
ca8f86a07f
commit
9ad407755b
5 changed files with 104 additions and 0 deletions
16
internal/api/agent/server.go
Normal file
16
internal/api/agent/server.go
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
package agentapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Start(address string) {
|
||||||
|
mux := http.NewServeMux()
|
||||||
|
mux.HandleFunc("/vpcs", VpcsHandler)
|
||||||
|
mux.HandleFunc("/vpcs/", VpcByNameHandler)
|
||||||
|
mux.HandleFunc("/subnets", SubnetsHandler)
|
||||||
|
mux.HandleFunc("/subnets/", SubnetByNameHandler)
|
||||||
|
log.Printf("API server listening on %s", address)
|
||||||
|
log.Fatal(http.ListenAndServe(address, mux))
|
||||||
|
}
|
||||||
25
internal/api/agent/subnet.go
Normal file
25
internal/api/agent/subnet.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
19
internal/api/agent/subnets.go
Normal file
19
internal/api/agent/subnets.go
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
package agentapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SubnetsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
switch r.Method {
|
||||||
|
case http.MethodGet:
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
json.NewEncoder(w).Encode([]interface{}{})
|
||||||
|
case http.MethodPost:
|
||||||
|
w.WriteHeader(http.StatusAccepted)
|
||||||
|
default:
|
||||||
|
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||||
|
}
|
||||||
|
}
|
||||||
25
internal/api/agent/vpc.go
Normal file
25
internal/api/agent/vpc.go
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
package agentapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func VpcByNameHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
name := strings.TrimPrefix(r.URL.Path, "/vpcs/")
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
19
internal/api/agent/vpcs.go
Normal file
19
internal/api/agent/vpcs.go
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
package agentapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func VpcsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
switch r.Method {
|
||||||
|
case http.MethodGet:
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
json.NewEncoder(w).Encode([]interface{}{})
|
||||||
|
case http.MethodPost:
|
||||||
|
w.WriteHeader(http.StatusAccepted)
|
||||||
|
default:
|
||||||
|
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue