diff --git a/cmd/backend/main.go b/cmd/backend/main.go index b4a9bad..2e7cb49 100644 --- a/cmd/backend/main.go +++ b/cmd/backend/main.go @@ -1,42 +1,15 @@ package main import ( - "flag" - "github.com/x0ddf/tiny-status-page/pkg/utils" + "github.com/x0ddf/tiny-status-page/pkg/server" "log" "net/http" "os" - "path/filepath" - - "k8s.io/client-go/tools/clientcmd" - "k8s.io/client-go/util/homedir" - - "github.com/x0ddf/tiny-status-page/pkg/server" - "k8s.io/client-go/rest" ) const DefaultPort = "8080" const PortVar = "PORT" -func getKubeConfig() (*rest.Config, error) { - // Try in-cluster config first - if utils.IsRunningInCluster() { - return rest.InClusterConfig() - } - - // Fallback to local kubeconfig - var kubeconfig *string - if home := homedir.HomeDir(); home != "" { - kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file") - } else { - kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file") - } - flag.Parse() - - // use the current context in kubeconfig - return clientcmd.BuildConfigFromFlags("", *kubeconfig) -} - func main() { var port string if port = os.Getenv(PortVar); port == "" { diff --git a/pkg/server/context_handler.go b/pkg/server/context_handler.go index 6407987..823948f 100644 --- a/pkg/server/context_handler.go +++ b/pkg/server/context_handler.go @@ -41,7 +41,11 @@ func (s *Server) HandleContextList(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(response) + encoder := json.NewEncoder(w) + err = encoder.Encode(response) + if err != nil { + return + } } func (s *Server) HandleContextSwitch(w http.ResponseWriter, r *http.Request) {