Load sheet into in-memory data model and serve it as the API

This commit is contained in:
Ian Gulliver
2026-08-15 16:22:25 -07:00
parent ba8d3d6fe4
commit 97af37ba40
10 changed files with 513 additions and 87 deletions
+21 -1
View File
@@ -10,9 +10,29 @@ import (
"heliosian/internal/directory"
)
func directorySource() data.Source {
sheetID := os.Getenv("DIRECTORY_SHEET")
if sheetID == "" {
return data.Dir{Root: "sampledata"}
}
keyFile, err := data.KeyFile()
if err != nil {
log.Fatalf("[ERROR] %v", err)
}
source, err := data.NewSheet(keyFile, map[string]string{"directory": sheetID})
if err != nil {
log.Fatalf("[ERROR] load directory sheet: %v", err)
}
return source
}
func main() {
cache, err := directory.NewCache(directorySource())
if err != nil {
log.Fatalf("[ERROR] load directory data: %v", err)
}
mux := http.NewServeMux()
directory.Register(mux, data.Dir{Root: "sampledata"})
directory.Register(mux, cache)
mux.Handle("GET /{$}", http.RedirectHandler("/directory/", http.StatusFound))
port := os.Getenv("PORT")
if port == "" {