refactor: use a centralized list key for enabled protocols

This commit is contained in:
Derrick Hammer 2024-01-28 02:58:33 -05:00
parent f7057142eb
commit 8c89796341
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 6 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"git.lumeweb.com/LumeWeb/portal/api/registry"
"git.lumeweb.com/LumeWeb/portal/api/router"
"github.com/samber/lo"
"github.com/spf13/viper"
"go.uber.org/fx"
)
@ -28,8 +29,9 @@ func getModulesBasedOnConfig() []fx.Option {
func BuildApis(config *viper.Viper) fx.Option {
var options []fx.Option
enabledProtocols := config.GetStringSlice("core.protocols")
for _, entry := range registry.GetRegistry() {
if config.GetBool("protocols." + entry.Key + ".enabled") {
if lo.Contains(enabledProtocols, entry.Key) {
options = append(options, entry.Module)
if entry.InitFunc != nil {
options = append(options, fx.Invoke(entry.InitFunc))

View File

@ -3,6 +3,7 @@ package protocols
import (
"context"
"git.lumeweb.com/LumeWeb/portal/protocols/registry"
"github.com/samber/lo"
"github.com/spf13/viper"
"go.uber.org/fx"
)
@ -17,8 +18,9 @@ func RegisterProtocols() {
func BuildProtocols(config *viper.Viper) fx.Option {
var options []fx.Option
enabledProtocols := config.GetStringSlice("core.protocols")
for _, entry := range registry.GetRegistry() {
if config.GetBool("protocols." + entry.Key + ".enabled") {
if lo.Contains(enabledProtocols, entry.Key) {
options = append(options, entry.Module)
if entry.InitFunc != nil {
options = append(options, fx.Invoke(entry.InitFunc))