aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Crute <mike@crute.us>2023-10-18 12:51:44 -0700
committerMike Crute <mike@crute.us>2023-10-18 12:51:44 -0700
commit72bf9d0a62c8459ce7c832298c723656e7e6d384 (patch)
tree4b3f32f2f16ebb50cbf3fa76626466632a3f392f
parent925de3239c9eab61a3a1275a554508f46a172709 (diff)
downloadgolib-72bf9d0a62c8459ce7c832298c723656e7e6d384.tar.bz2
golib-72bf9d0a62c8459ce7c832298c723656e7e6d384.tar.xz
golib-72bf9d0a62c8459ce7c832298c723656e7e6d384.zip
echo: support more correct disk templatesecho/v0.15.1
-rw-r--r--echo/echo_default.go25
1 files changed, 20 insertions, 5 deletions
diff --git a/echo/echo_default.go b/echo/echo_default.go
index 8440fe2..aa9e32a 100644
--- a/echo/echo_default.go
+++ b/echo/echo_default.go
@@ -7,6 +7,7 @@ import (
7 "html/template" 7 "html/template"
8 "io/fs" 8 "io/fs"
9 "net/http" 9 "net/http"
10 "os"
10 "sync" 11 "sync"
11 12
12 "code.crute.us/mcrute/golib/clients/netbox" 13 "code.crute.us/mcrute/golib/clients/netbox"
@@ -61,6 +62,7 @@ type EchoConfig struct {
61 TrustedProxyIPRanges []string 62 TrustedProxyIPRanges []string
62 EmbeddedTemplates fs.FS 63 EmbeddedTemplates fs.FS
63 DiskTemplates fs.FS 64 DiskTemplates fs.FS
65 DiskTemplatesPath string
64 ProvideTemplateStore []WantsTemplateStore 66 ProvideTemplateStore []WantsTemplateStore
65 TemplateFunctions template.FuncMap 67 TemplateFunctions template.FuncMap
66 CombinedHostLogFile string 68 CombinedHostLogFile string
@@ -218,12 +220,25 @@ func (w *EchoWrapper) configureIpExtractor(c *EchoConfig) error {
218} 220}
219 221
220func (w *EchoWrapper) configureTemplates(c *EchoConfig) error { 222func (w *EchoWrapper) configureTemplates(c *EchoConfig) error {
221 // Use templates from disk in debug mode and the embedded ones that are 223 // TODO: v1, deprecate DiskTemplates
222 // built-in to the binary for prod mode.
223 var templates fs.FS 224 var templates fs.FS
224 225 if (c.DiskTemplatesPath != "" || c.DiskTemplates != nil) && w.Debug { // Debug Mode
225 if c.DiskTemplates != nil && w.Debug { // Debug Mode 226 // If the fs.FS for DiskTemplates is provided use that
226 templates = c.DiskTemplates 227 if c.DiskTemplates != nil {
228 w.Logger.Debug("Debug mode, using disk templates from passed fs.FS")
229 w.Logger.Warn("Using disk templates from an fs.FS is deprecated behavior")
230 templates = c.DiskTemplates
231 } else {
232 // Use templates from disk in debug mode and the embedded ones that are
233 // built-in to the binary for prod mode.
234 if _, err := os.Stat(c.DiskTemplatesPath); err == nil {
235 w.Logger.Debug("Debug mode, using disk templates from filesystem")
236 templates = os.DirFS(c.DiskTemplatesPath)
237 } else {
238 w.Logger.Warnf("Disk templates not found, using embedded templates only")
239 templates = c.EmbeddedTemplates
240 }
241 }
227 } else if c.EmbeddedTemplates != nil { // Prod Mode 242 } else if c.EmbeddedTemplates != nil { // Prod Mode
228 templates = c.EmbeddedTemplates 243 templates = c.EmbeddedTemplates
229 } 244 }