package mainimport ( "encoding/json" // "flag" //"fmt" "strconv" "html/template" "time" // "log" "strings" "net/http" "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/clientcmd")type microservice_details struct{ Deployment_name string `json:"Deployment_name"` Namespace string `json:"Namespace"` Image_tag string}type namespace_details struct { Namespace []string }var templates = template.Must(template.ParseGlob("./*.html"))var label_name stringvar namespace stringvar microservice ="/microservice/"var detailed_view="/detailed/"var kube_config_path="/home/saivamsi/.kube/config"var config, _ = clientcmd.BuildConfigFromFlags("", kube_config_path)var clientset, _ = kubernetes.NewForConfig(config)func main() { templates = template.Must(template.ParseGlob("./*.html")) http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("css")))) http.Handle("/jpeg/", http.StripPrefix("/jpeg/", http.FileServer(http.Dir("css")))) http.HandleFunc("/", homepage) http.HandleFunc(microservice, Deployment) http.ListenAndServe(":8801",nil)}func homepage(w http.ResponseWriter, r *http.Request){ namespace,_:=clientset.CoreV1().Namespaces().List(v1.ListOptions{}) namespace_tmp := namespace_details{} for _,s := range namespace.Items{ namespace_tmp.Namespace = append(namespace_tmp.Namespace,s.Name) } templates.ExecuteTemplate(w,"homepage2.html",namespace_tmp)}如何在部署函数中使用主页函数的命名空间变量。我需要在 go 模板中使用它们。我必须在 microservices.html 中使用该命名空间。我尝试了很多东西但没有奏效。
- 1 回答
- 0 关注
- 151 浏览
添加回答
举报
0/150
提交
取消