fix: added check to loadTargets() to prevent panic

This commit is contained in:
David Allen 2024-12-18 11:33:48 -07:00
parent 235efcdd07
commit 2edd8367bc
Signed by: towk
GPG key ID: 793B2924A49B3A3F

View file

@ -186,11 +186,17 @@ func (s *Server) Generate(opts ...client.Option) func(w http.ResponseWriter, r *
} }
func (s *Server) loadTargets() { func (s *Server) loadTargets() {
// make sure the map is initialized first
if s.Targets == nil {
s.Targets = make(map[string]Target)
}
// add targets from config to server
for name, target := range s.Config.Targets { for name, target := range s.Config.Targets {
serverTarget := Target{ serverTarget := Target{
Name: name, Name: name,
PluginPath: target.Plugin, PluginPath: target.Plugin,
} }
// add templates using template paths from config
for _, templatePath := range target.TemplatePaths { for _, templatePath := range target.TemplatePaths {
template := generator.Template{} template := generator.Template{}
template.LoadFromFile(templatePath) template.LoadFromFile(templatePath)