Skip to content

Commit

Permalink
lint err
Browse files Browse the repository at this point in the history
  • Loading branch information
x0ddf committed Nov 25, 2024
1 parent aa8f4b8 commit 5456dce
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 29 deletions.
29 changes: 1 addition & 28 deletions cmd/backend/main.go
Original file line number Diff line number Diff line change
@@ -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 == "" {
Expand Down
6 changes: 5 additions & 1 deletion pkg/server/context_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 5456dce

Please sign in to comment.