Skip to content

Commit

Permalink
linter
Browse files Browse the repository at this point in the history
Signed-off-by: Gergely Brautigam <[email protected]>
  • Loading branch information
Skarlso committed Jan 3, 2025
1 parent c1bb2a5 commit f97c203
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 33 deletions.
4 changes: 2 additions & 2 deletions cmd/git_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 0 additions & 2 deletions wasm/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
25 changes: 17 additions & 8 deletions wasm/cors_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -70,15 +77,17 @@ 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
}
}

func (p *CorsProxy) Serve() *http.Server {
return &http.Server{
Addr: ":8999",
Handler: p,
Addr: ":8999",
Handler: p,
ReadHeaderTimeout: headerTimeout,
ReadTimeout: readTimeout,
}
}
4 changes: 2 additions & 2 deletions wasm/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != ""
}
Expand Down Expand Up @@ -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(),
Expand Down
16 changes: 8 additions & 8 deletions wasm/index.html
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
<!doctype html>
<html data-bs-theme="dark" lang="en" data-bs-core="modern">
<html data-bs-core="modern" data-bs-theme="dark" lang="en">
<head>
<meta charset="UTF-8">
<meta name="author" content="Gergely Brautigam">
<meta content="Gergely Brautigam" name="author">
<meta name="description" content>
<meta name="theme-color" content="#2d2c2c">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta property="og:url" content="https://">
<meta property="og:title" content="Preview CRDs">
<meta property="og:description" content>
<meta property="og:type" content="website">
<meta content="website" property="og:type">
<meta property="og:image" content="https://">
<title>Preview CRDs</title>
<link rel="icon" href="https://raw.githubusercontent.com/maxence-charriere/go-app/master/docs/web/icon.svg">
<link rel="apple-touch-icon" href="/web/img/logo.png">
<link rel="manifest" href="/manifest.webmanifest">
<link href="/app.css" type="text/css" rel="stylesheet">
<link rel="stylesheet" href="/web/css/alert.css" type="text/css">
<link href="/web/css/alert.css" type="text/css" rel="stylesheet">
<link href="/web/css/yaml.css" type="text/css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/css/halfmoon.min.css" type="text/css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/css/cores/halfmoon.modern.css" type="text/css" rel="stylesheet">
<link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/cores/halfmoon.modern.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css" rel="stylesheet">
<script defer src="/wasm_exec.js"></script>
<script defer src="/app.js"></script>
<script src="/app.js" defer></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.11/clipboard.min.js"></script>
<meta charset="utf-8">
Expand Down Expand Up @@ -57,8 +57,8 @@
</head>
<body>
<main></main>
<aside id="app-wasm-loader" class="goapp-app-info">
<img id="app-wasm-loader-icon" class="goapp-logo goapp-spin" alt="wasm loader icon" src="/web/img/logo.png">
<aside class="goapp-app-info" id="app-wasm-loader">
<img src="/web/img/logo.png" id="app-wasm-loader-icon" class="goapp-logo goapp-spin" alt="wasm loader icon">
<p id="app-wasm-loader-label" class="goapp-label">0%</p>
</aside>
</body>
Expand Down
10 changes: 4 additions & 6 deletions wasm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"log"
"net/http"
"os"

Expand Down Expand Up @@ -112,12 +111,11 @@ func main() {

proxy := NewCorsProxy()
server := proxy.Serve()
go server.ListenAndServe()
defer server.Shutdown(context.Background())
go func() { _ = server.ListenAndServe() }()
defer func() { _ = server.Shutdown(context.Background()) }()

//nolint: gosec // it's fine
if err := http.ListenAndServe(":8000", nil); err != nil {
log.Fatal(err)
if err := http.ListenAndServe(":8000", nil); err != nil { //nolint:gosec // it's fine
panic(err)
}
}

Expand Down
8 changes: 4 additions & 4 deletions wasm/share.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!doctype html>
<html data-bs-core="modern" data-bs-theme="dark" lang="en">
<html lang="en" data-bs-core="modern" data-bs-theme="dark">
<head>
<meta charset="UTF-8">
<meta name="author" content="Gergely Brautigam">
<meta name="description" content>
<meta name="theme-color" content="#2d2c2c">
<meta content="#2d2c2c" name="theme-color">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta property="og:url" content="https:///share">
Expand All @@ -17,7 +17,7 @@
<link rel="apple-touch-icon" href="/web/img/logo.png">
<link rel="manifest" href="/manifest.webmanifest">
<link href="/app.css" type="text/css" rel="stylesheet">
<link type="text/css" rel="stylesheet" href="/web/css/alert.css">
<link href="/web/css/alert.css" type="text/css" rel="stylesheet">
<link href="/web/css/yaml.css" type="text/css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/css/halfmoon.min.css" type="text/css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/css/cores/halfmoon.modern.css" type="text/css" rel="stylesheet">
Expand Down Expand Up @@ -61,7 +61,7 @@
<h4 class="alert-heading">Oops!</h4>
url parameter has to be define in the following format: /share?url=https://example.com/crd.yaml
</div>
<aside id="app-wasm-loader" class="goapp-app-info">
<aside class="goapp-app-info" id="app-wasm-loader">
<img src="/web/img/logo.png" id="app-wasm-loader-icon" class="goapp-logo goapp-spin" alt="wasm loader icon">
<p id="app-wasm-loader-label" class="goapp-label">0%</p>
</aside>
Expand Down
Binary file modified wasm/web/app.wasm
Binary file not shown.

0 comments on commit f97c203

Please sign in to comment.