fix: added function to load server targets from config

This commit is contained in:
David Allen 2024-12-17 16:29:02 -07:00
parent 4ff8094988
commit 235efcdd07
Signed by: towk
GPG key ID: 793B2924A49B3A3F

View file

@ -55,8 +55,7 @@ func New(conf *config.Config) *Server {
c := config.New() c := config.New()
conf = &c conf = &c
} }
// return based on config values newServer := &Server{
return &Server{
Config: conf, Config: conf,
Server: &http.Server{Addr: conf.Server.Host}, Server: &http.Server{Addr: conf.Server.Host},
Jwks: Jwks{ Jwks: Jwks{
@ -64,6 +63,9 @@ func New(conf *config.Config) *Server {
Retries: conf.Server.Jwks.Retries, Retries: conf.Server.Jwks.Retries,
}, },
} }
// load templates for server from config
newServer.loadTargets()
return newServer
} }
// Main function to start up configurator as a service. // Main function to start up configurator as a service.
@ -183,6 +185,21 @@ func (s *Server) Generate(opts ...client.Option) func(w http.ResponseWriter, r *
} }
} }
func (s *Server) loadTargets() {
for name, target := range s.Config.Targets {
serverTarget := Target{
Name: name,
PluginPath: target.Plugin,
}
for _, templatePath := range target.TemplatePaths {
template := generator.Template{}
template.LoadFromFile(templatePath)
serverTarget.Templates = append(serverTarget.Templates, template)
}
s.Targets[name] = serverTarget
}
}
// Create a new target with name, generator, templates, and files. // Create a new target with name, generator, templates, and files.
// //
// Example: // Example: