fix: added function to load server targets from config
This commit is contained in:
parent
4ff8094988
commit
235efcdd07
1 changed files with 19 additions and 2 deletions
|
|
@ -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:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue