nidus-sync/sync/page.go
Eli Ribble cf06bb9f49
Break apart sync into parts more like public-reports
I like this layout makes it easier to track what functions do what and
keeps templates near their render functions.
2026-01-13 20:30:57 +00:00

36 lines
965 B
Go

package sync
import (
"embed"
"fmt"
"net/http"
"github.com/Gleipnir-Technology/nidus-sync/htmlpage"
"github.com/rs/zerolog/log"
)
//go:embed template/*
var embeddedFiles embed.FS
//go:embed static/*
var EmbeddedStaticFS embed.FS
var components = [...]string{"header", "map"}
func buildTemplate(files ...string) *htmlpage.BuiltTemplate {
subdir := "sync"
full_files := make([]string, 0)
for _, f := range files {
full_files = append(full_files, fmt.Sprintf("%s/template/%s.html", subdir, f))
}
for _, c := range components {
full_files = append(full_files, fmt.Sprintf("%s/template/components/%s.html", subdir, c))
}
return htmlpage.NewBuiltTemplate(embeddedFiles, "sync/", full_files...)
}
// Respond with an error that is visible to the user
func respondError(w http.ResponseWriter, m string, e error, s int) {
log.Warn().Int("status", s).Err(e).Str("user message", m).Msg("Responding with an error from sync pages")
http.Error(w, m, s)
}