config-vars.go 803 B

1234567891011121314151617181920212223242526272829303132333435
  1. package servtools
  2. import (
  3. _ "embed"
  4. "html/template"
  5. "net/http"
  6. "github.com/vladimirok5959/golang-utils/utils/http/render"
  7. "github.com/vladimirok5959/golang-utils/utils/penv"
  8. )
  9. var (
  10. //go:embed config-vars.html
  11. configVarsHtml string
  12. )
  13. // config - must be a pointer to config structure
  14. func ConfigVars(config any) http.Handler {
  15. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  16. if !render.HTML(
  17. w,
  18. r,
  19. template.FuncMap{
  20. "secret": func(value string) template.HTML {
  21. return template.HTML(`<span onclick="if(this.innerHTML=='**********'){this.innerHTML='` + value + `';}else{this.innerHTML='**********';}" style="cursor:pointer;">**********</span>`)
  22. },
  23. },
  24. penv.DumpConfig(config),
  25. configVarsHtml,
  26. http.StatusOK,
  27. ) {
  28. return
  29. }
  30. })
  31. }