From e91187ee96e4c5db9197c2617b6335413b1ee13b Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Thu, 28 Mar 2024 13:19:53 +0100 Subject: pkg/html: add more flexibility to glob paths The current logic restricts the callers too much. Make it possible to override the base path for templates. --- pkg/html/html.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'pkg/html') diff --git a/pkg/html/html.go b/pkg/html/html.go index 7e52d3930..efb8c01b2 100644 --- a/pkg/html/html.go +++ b/pkg/html/html.go @@ -18,16 +18,21 @@ import ( "google.golang.org/appengine/v2" ) -// searchPath differs for the tests and AppEngine because we don't follow +// search path differs for the tests and AppEngine because we don't follow // the recommended folder structure (my best guess). // When you run the dashboard/app tests, CWD is syzkaller/dashboard/app. // When you deploy AppEngine in the GOPATH mode, CWD is syzkaller/dashboard/app. // When you deploy AppEngine in the GOMOD, CWD is syzkaller/. -func globSearchPath() string { +var globSearchPath = func() string { if appengine.IsAppEngine() { return "dashboard/app/" } return "" +}() + +// SetGlobSearchPath overrides the default path where syzkaller looks for templates. +func SetGlobSearchPath(path string) { + globSearchPath = path } func CreateGlob(glob string) *template.Template { @@ -35,7 +40,7 @@ func CreateGlob(glob string) *template.Template { panic("glob can't be a path, the files mask is expected") } return template.Must( - template.New("").Funcs(Funcs).ParseGlob(globSearchPath() + glob)) + template.New("").Funcs(Funcs).ParseGlob(filepath.Join(globSearchPath, glob))) } func CreateTextGlob(glob string) *texttemplate.Template { @@ -43,7 +48,7 @@ func CreateTextGlob(glob string) *texttemplate.Template { panic("glob can't be a path, the files mask is expected") } return texttemplate.Must( - texttemplate.New("").Funcs(Funcs).ParseGlob(globSearchPath() + glob)) + texttemplate.New("").Funcs(Funcs).ParseGlob(filepath.Join(globSearchPath, glob))) } var Funcs = template.FuncMap{ -- cgit mrf-deployment