This commit is contained in:
unknown
2025-05-11 20:18:33 +03:30
parent 61a9fbe9f2
commit 7bc33a8808
5 changed files with 119 additions and 19 deletions

View File

@@ -5,9 +5,10 @@ import (
"encoding/json"
"main/argohandler"
"main/db"
"net/http"
"net/http"
"log"
"github.com/gorilla/mux"
// "github.com/gorilla/mux"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)
@@ -24,11 +25,22 @@ type Cluster struct {
UserID primitive.ObjectID `json:"userId"`
}
func createClusterHandler(w http.ResponseWriter, r *http.Request) {
type Header struct {
Authorization string `bson:"token"`
}
func CreateClusterHandler(w http.ResponseWriter, r *http.Request) {
var cluster Cluster
_ = json.NewDecoder(r.Body).Decode(&cluster)
var header Header
header.Authorization = r.Header.Get("Authorization")
log.Fatal("--------------")
log.Fatal(r.Header.Get("Authorization"))
log.Fatal("--------------")
// vclusterCollection := db.Vclusters_details.FindOne(context.TODO(), bson.M{"name": Cluster.Name}).Decode(&existsCluster)
if cluster.Name == "" || cluster.ControlPlane == "" || cluster.PlatformVersion == "" || cluster.Cpu == "" || cluster.Memory == "" {
@@ -49,7 +61,7 @@ func createClusterHandler(w http.ResponseWriter, r *http.Request) {
http.Error(w, `{"message": "Could not create cluster"}`, http.StatusInternalServerError)
}
argohandler.CreateApp(cluster.Name)
argohandler.CreateApp(cluster.Name, cluster.ControlPlane, cluster.PlatformVersion, cluster.Cpu, cluster.Memory, "userid")
response := map[string]string{"message": "Cluster created"}
@@ -58,6 +70,6 @@ func createClusterHandler(w http.ResponseWriter, r *http.Request) {
}
func RegsiterClusterRoute(r *mux.Router) {
r.HandleFunc("/createcluster", createClusterHandler).Methods("POST")
}
// func RegsiterClusterRoute(r *mux.Router) {
// r.HandleFunc("/createcluster", createClusterHandler).Methods("POST", "OPTIONS")
// }