diff --git a/cmd/git_handler.go b/cmd/git_handler.go index c1e0f9c..ebf6f59 100644 --- a/cmd/git_handler.go +++ b/cmd/git_handler.go @@ -49,7 +49,7 @@ func (g *GitHandler) CRDs() ([]*pkg.SchemaType, error) { ref, err = r.Head() } if err != nil { - return nil, fmt.Errorf("failed to construct reference: %v", err) + return nil, fmt.Errorf("failed to construct reference: %w", err) } crds, err := gatherSchemaTypesForRef(r, ref) @@ -71,7 +71,7 @@ func gatherSchemaTypesForRef(r *git.Repository, ref *plumbing.Reference) ([]*pkg commit, err := r.CommitObject(*hash) if err != nil { - return nil, fmt.Errorf("error getting commit object: %v", err) + return nil, fmt.Errorf("error getting commit object: %w", err) } commitTree, err := commit.Tree() diff --git a/go.mod b/go.mod index ac19a09..bf857b3 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,6 @@ require ( github.com/maxence-charriere/go-app/v10 v10.0.9 github.com/spf13/cobra v1.8.1 github.com/stretchr/testify v1.10.0 - golang.org/x/sync v0.10.0 k8s.io/apiextensions-apiserver v0.32.0 k8s.io/apimachinery v0.32.0 ) diff --git a/wasm/app.go b/wasm/app.go index 3279213..fd6920b 100644 --- a/wasm/app.go +++ b/wasm/app.go @@ -22,11 +22,9 @@ type crdView struct { app.Compo preRenderErr error - //content []byte crds []*pkg.SchemaType comment bool minimal bool - useGit bool navigateBackOnClick func(ctx app.Context, _ app.Event) } diff --git a/wasm/cors_proxy.go b/wasm/cors_proxy.go index dd448d8..bed3304 100644 --- a/wasm/cors_proxy.go +++ b/wasm/cors_proxy.go @@ -8,6 +8,12 @@ import ( "time" ) +const ( + headerTimeout = 5 * time.Second + readTimeout = 20 * time.Second + clientTimeout = time.Second * 30 +) + type CorsProxy struct{} func NewCorsProxy() *CorsProxy { @@ -19,7 +25,7 @@ func (p *CorsProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE") w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding") w.Header().Set("Access-Control-Allow-Credentials", "true") - if r.Method == "OPTIONS" { + if r.Method == http.MethodOptions { w.WriteHeader(http.StatusOK) return @@ -28,14 +34,15 @@ func (p *CorsProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { targetURL := r.URL.Query().Get("url") if targetURL == "" { http.Error(w, "Missing 'url' parameter", http.StatusBadRequest) + return } // create the request to server - req, err := http.NewRequest(r.Method, targetURL, r.Body) + req, err := http.NewRequestWithContext(r.Context(), r.Method, targetURL, r.Body) if err != nil { w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte(err.Error())) + _, _ = w.Write([]byte(err.Error())) return } @@ -49,12 +56,12 @@ func (p *CorsProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { // create a basic client to send the request client := http.Client{ - Timeout: time.Second * 30, + Timeout: clientTimeout, } resp, err := client.Do(req) if err != nil { w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte(err.Error())) + _, _ = w.Write([]byte(err.Error())) return } @@ -70,7 +77,7 @@ func (p *CorsProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { _, err = io.Copy(w, resp.Body) if err != nil { w.WriteHeader(http.StatusInternalServerError) - w.Write([]byte(err.Error())) + _, _ = w.Write([]byte(err.Error())) return } @@ -78,7 +85,9 @@ func (p *CorsProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (p *CorsProxy) Serve() *http.Server { return &http.Server{ - Addr: ":8999", - Handler: p, + Addr: ":8999", + Handler: p, + ReadHeaderTimeout: headerTimeout, + ReadTimeout: readTimeout, } } diff --git a/wasm/index.go b/wasm/index.go index a8ecffb..9b06e46 100644 --- a/wasm/index.go +++ b/wasm/index.go @@ -152,7 +152,7 @@ func (f *form) Render() app.UI { ) } -func (f *form) OnInput(ctx app.Context, e app.Event) { +func (f *form) OnInput(ctx app.Context, _ app.Event) { content := ctx.JSSrc().Get("value").String() f.warningHidden = content != "" } @@ -213,7 +213,7 @@ func (i *index) OnClick(ctx app.Context, _ app.Event) { gitURL := app.Window().GetElementByID("git_url").Get("value") if v := gitURL.String(); v != "" { tag := app.Window().GetElementByID("url_tag").Get("value") - u := fmt.Sprintf("http://localhost:8999?url=%s", v) + u := "http://localhost:8999?url=" + v g := cmd.GitHandler{ URL: u, Username: username.String(), diff --git a/wasm/index.html b/wasm/index.html index 52cf1a9..1706d6b 100644 --- a/wasm/index.html +++ b/wasm/index.html @@ -1,8 +1,8 @@ - + - + @@ -10,20 +10,20 @@ - + Preview CRDs - + - + - + @@ -57,8 +57,8 @@
-