make runset a map

Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
jkoberg committed 2022-07-21 16:19:36 +02:00
1 parent db363b6800
commit f64ea7dc1b
2 files changed
+15 -19

No files matched your search

+2 -2
View File
@@ -49,8 +49,8 @@ type Mode int
type Runtime struct { type Runtime struct {
Port string `yaml:"port" env:"OCIS_RUNTIME_PORT"` Port string `yaml:"port" env:"OCIS_RUNTIME_PORT"`
Host string `yaml:"host" env:"OCIS_RUNTIME_HOST"` Host string `yaml:"host" env:"OCIS_RUNTIME_HOST"`
Extensions string `yaml:"services" env:"OCIS_RUN_EXTENSIONS;OCIS_RUN_SERVICES" desc:"Expects a space separated list of service names. Will start only the listed services."` Extensions string `yaml:"services" env:"OCIS_RUN_EXTENSIONS;OCIS_RUN_SERVICES" desc:"Expects a comma separated list of service names. Will start only the listed services."`
Disabled string `yaml:"disabled_services" env:"OCIS_EXCLUDE_RUN_SERVICES" desc:"Expects a space separated list of service names. Will start all services except for the ones listed. Has no effect when OCIS_RUN_SERVICES is set."` Disabled string `yaml:"disabled_services" env:"OCIS_EXCLUDE_RUN_SERVICES" desc:"Expects a comma separated list of service names. Will start all services except of the ones listed. Has no effect when OCIS_RUN_SERVICES is set."`
} }
// Config combines all available configuration parts. // Config combines all available configuration parts.
+13 -17
View File
@@ -54,7 +54,7 @@ import (
var ( var (
// runset keeps track of which extensions to start supervised. // runset keeps track of which extensions to start supervised.
runset []string runset map[string]struct{}
) )
type serviceFuncMap map[string]func(*ociscfg.Config) suture.Service type serviceFuncMap map[string]func(*ociscfg.Config) suture.Service
@@ -227,7 +227,7 @@ func Start(o ...Option) error {
// scheduleServiceTokens adds service tokens to the service supervisor. // scheduleServiceTokens adds service tokens to the service supervisor.
func scheduleServiceTokens(s *Service, funcSet serviceFuncMap) { func scheduleServiceTokens(s *Service, funcSet serviceFuncMap) {
for _, name := range runset { for name := range runset {
if _, ok := funcSet[name]; !ok { if _, ok := funcSet[name]; !ok {
continue continue
} }
@@ -240,31 +240,27 @@ func scheduleServiceTokens(s *Service, funcSet serviceFuncMap) {
// generateRunSet interprets the cfg.Runtime.Extensions config option to cherry-pick which services to start using // generateRunSet interprets the cfg.Runtime.Extensions config option to cherry-pick which services to start using
// the runtime. // the runtime.
func (s *Service) generateRunSet(cfg *ociscfg.Config) { func (s *Service) generateRunSet(cfg *ociscfg.Config) {
runset = make(map[string]struct{})
if cfg.Runtime.Extensions != "" { if cfg.Runtime.Extensions != "" {
e := strings.Split(strings.ReplaceAll(cfg.Runtime.Extensions, " ", ""), ",") e := strings.Split(strings.ReplaceAll(cfg.Runtime.Extensions, " ", ""), ",")
for i := range e { for _, name := range e {
runset = append(runset, e[i]) runset[name] = struct{}{}
} }
return return
} }
disabled := make(map[string]bool)
if cfg.Runtime.Disabled != "" {
e := strings.Split(strings.ReplaceAll(cfg.Runtime.Disabled, " ", ""), ",")
for _, s := range e {
disabled[s] = true
}
}
for name := range s.ServicesRegistry { for name := range s.ServicesRegistry {
if !disabled[name] { runset[name] = struct{}{}
runset = append(runset, name)
}
} }
for name := range s.Delayed { for name := range s.Delayed {
if !disabled[name] { runset[name] = struct{}{}
runset = append(runset, name) }
if cfg.Runtime.Disabled != "" {
e := strings.Split(strings.ReplaceAll(cfg.Runtime.Disabled, " ", ""), ",")
for _, name := range e {
delete(runset, name)
} }
} }
} }