refactor: switch to using package init functions with build tags to selectively build protocol support

This commit is contained in:
Derrick Hammer 2024-02-17 07:40:22 -05:00
parent f73ad52864
commit 162af1e274
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
6 changed files with 44 additions and 25 deletions

13
api/account.go Normal file
View File

@ -0,0 +1,13 @@
package api
import (
"git.lumeweb.com/LumeWeb/portal/api/account"
"git.lumeweb.com/LumeWeb/portal/api/registry"
)
func init() {
registry.Register(registry.APIEntry{
Key: "account",
Module: account.Module,
})
}

View File

@ -6,24 +6,11 @@ import (
"git.lumeweb.com/LumeWeb/portal/api/middleware" "git.lumeweb.com/LumeWeb/portal/api/middleware"
"git.lumeweb.com/LumeWeb/portal/api/account"
"git.lumeweb.com/LumeWeb/portal/api/registry" "git.lumeweb.com/LumeWeb/portal/api/registry"
"git.lumeweb.com/LumeWeb/portal/api/s5"
"github.com/spf13/viper" "github.com/spf13/viper"
"go.uber.org/fx" "go.uber.org/fx"
) )
func RegisterApis() {
registry.Register(registry.APIEntry{
Key: "s5",
Module: s5.Module,
})
registry.Register(registry.APIEntry{
Key: "account",
Module: account.Module,
})
}
func BuildApis(config *viper.Viper) fx.Option { func BuildApis(config *viper.Viper) fx.Option {
var options []fx.Option var options []fx.Option
enabledProtocols := config.GetStringSlice("core.protocols") enabledProtocols := config.GetStringSlice("core.protocols")

15
api/s5.go Normal file
View File

@ -0,0 +1,15 @@
//go:build s5
package api
import (
"git.lumeweb.com/LumeWeb/portal/api/registry"
"git.lumeweb.com/LumeWeb/portal/api/s5"
)
func init() {
registry.Register(registry.APIEntry{
Key: "s5",
Module: s5.Module,
})
}

View File

@ -34,9 +34,6 @@ func main() {
flag.BoolVar(&fxDebug, "fx-debug", false, "Enable fx framework debug logging") flag.BoolVar(&fxDebug, "fx-debug", false, "Enable fx framework debug logging")
flag.Parse() flag.Parse()
protocols.RegisterProtocols()
api.RegisterApis()
var fxLogger fx.Option var fxLogger fx.Option
fxLogger = fx.WithLogger(func(logger *zap.Logger) fxevent.Logger { fxLogger = fx.WithLogger(func(logger *zap.Logger) fxevent.Logger {

View File

@ -4,20 +4,11 @@ import (
"context" "context"
"git.lumeweb.com/LumeWeb/portal/protocols/registry" "git.lumeweb.com/LumeWeb/portal/protocols/registry"
"git.lumeweb.com/LumeWeb/portal/protocols/s5"
"github.com/samber/lo" "github.com/samber/lo"
"github.com/spf13/viper" "github.com/spf13/viper"
"go.uber.org/fx" "go.uber.org/fx"
) )
func RegisterProtocols() {
registry.Register(registry.ProtocolEntry{
Key: "s5",
Module: s5.ProtocolModule,
PreInitFunc: s5.PreInit,
})
}
func BuildProtocols(config *viper.Viper) fx.Option { func BuildProtocols(config *viper.Viper) fx.Option {
var options []fx.Option var options []fx.Option
enabledProtocols := config.GetStringSlice("core.protocols") enabledProtocols := config.GetStringSlice("core.protocols")

16
protocols/s5.go Normal file
View File

@ -0,0 +1,16 @@
//go:build s5
package protocols
import (
"git.lumeweb.com/LumeWeb/portal/protocols/registry"
"git.lumeweb.com/LumeWeb/portal/protocols/s5"
)
func init() {
registry.Register(registry.ProtocolEntry{
Key: "s5",
Module: s5.ProtocolModule,
PreInitFunc: s5.PreInit,
})
}