Files
zot/pkg/debug/gqlplayground/gqlplayground.go
T
Andrei Aaron da426850e7 chore: update golangci-lint and fix all issues (#3575)
* chore: Update golangci-lint

Signed-off-by: Lars Francke <git@lars-francke.de>

* chore: fix all golangci-lint issues

- Remove deprecated `// +build` tags
- Fix godoclint, modernize, wsl_v5, govet, lll, gci, noctx issues
- Update linter configuration
- Modernize code to use Go 1.22+ features (for range N, slices.Contains, etc.)
- Update make check lint the privileged tests

Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>

---------

Signed-off-by: Lars Francke <git@lars-francke.de>
Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>
Co-authored-by: Lars Francke <git@lars-francke.de>
2025-11-22 23:36:48 +02:00

52 lines
1.1 KiB
Go

//go:build debug
package debug
import (
"embed"
"html/template"
"net/http"
"github.com/gorilla/mux"
"zotregistry.dev/zot/v2/pkg/api/constants"
debugCst "zotregistry.dev/zot/v2/pkg/debug/constants"
"zotregistry.dev/zot/v2/pkg/log"
"zotregistry.dev/zot/v2/pkg/storage"
)
//go:embed index.html.tmpl
var playgroundHTML embed.FS
// SetupGQLPlaygroundRoutes ...
func SetupGQLPlaygroundRoutes(router *mux.Router,
storeController storage.StoreController, log log.Logger,
) {
log.Info().Msg("setting up graphql playground route")
templ, err := template.ParseFS(playgroundHTML, "index.html.tmpl")
if err != nil {
log.Fatal().Err(err).Msg("")
}
//nolint:lll
router.PathPrefix(debugCst.GQLPlaygroundEndpoint).HandlerFunc(func(writer http.ResponseWriter, req *http.Request) {
writer.Header().Add("Content-Type", "text/html")
proto := ""
if req.TLS == nil {
proto += "http://"
} else {
proto += "https://"
}
target := proto + req.Host + constants.FullSearchPrefix
// respond with the output of template execution
_ = templ.Execute(writer, struct {
Target string
}{Target: target})
})
}