package api import ( "encoding/json" "fmt" "net/http" "os" "scm/crt" "scm/model" ) func RootCert(w http.ResponseWriter, r *http.Request) { switch r.Method { case "GET": _, err := os.Stat(fmt.Sprintf("%s/%s", os.Getenv("CERTS_PATH"), "root/root.crt")) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } fmt.Fprintf(w, `{"status":"ok"}`) case "POST": var rootCertRequest model.CreateRootCertRequest err := json.NewDecoder(r.Body).Decode(&rootCertRequest) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return } err = crt.CreateRootKeyCertificate(rootCertRequest) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } fmt.Fprintf(w, `{"status":"ok"}`) default: http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) } }