Files
helix-proxy/internal/www/page.go
T
s1d3sw1ped 1cc94f2c99
Format / gofmt (push) Failing after 27s
CI / Build (push) Successful in 51s
CI / Go Tests (push) Failing after 21s
initial commit
2026-06-06 07:54:44 -05:00

35 lines
715 B
Go

package www
import (
"os"
"path/filepath"
"strings"
"helix-proxy/internal/config"
)
// LoadPage returns HTML for name (e.g. "index.html", "404.html").
// A file in WWW_DIR with the same name overrides the embedded default.
// Placeholders use the form {{KEY}} and are replaced from vars.
func LoadPage(name string, vars map[string]string) []byte {
wwwDir := config.Resolve("www")
customPath := filepath.Join(wwwDir, name)
data, err := os.ReadFile(customPath)
if err != nil {
data, err = defaults.ReadFile(name)
if err != nil {
return nil
}
}
if len(vars) == 0 {
return data
}
s := string(data)
for k, v := range vars {
s = strings.ReplaceAll(s, "{{"+k+"}}", v)
}
return []byte(s)
}