fix: break import cycle

This commit is contained in:
Derrick Hammer 2024-01-15 20:10:15 -05:00
parent 66e1cba39b
commit 2040d4edbc
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
5 changed files with 14 additions and 13 deletions

View File

@ -19,7 +19,7 @@ var (
type PortalImpl struct {
apiRegistry interfaces.APIRegistry
protocolRegistry protocols.ProtocolRegistry
protocolRegistry interfaces.ProtocolRegistry
logger *zap.Logger
identity ed25519.PrivateKey
storage interfaces.StorageService
@ -86,6 +86,6 @@ func (p *PortalImpl) SetIdentity(identity ed25519.PrivateKey) {
func (p *PortalImpl) SetLogger(logger *zap.Logger) {
p.logger = logger
}
func (p *PortalImpl) ProtocolRegistry() protocols.ProtocolRegistry {
func (p *PortalImpl) ProtocolRegistry() interfaces.ProtocolRegistry {
return p.protocolRegistry
}

View File

@ -2,7 +2,6 @@ package interfaces
import (
"crypto/ed25519"
"git.lumeweb.com/LumeWeb/portal/protocols"
"github.com/spf13/viper"
"go.uber.org/zap"
"gorm.io/gorm"
@ -15,7 +14,7 @@ type Portal interface {
Logger() *zap.Logger
Db() *gorm.DB
ApiRegistry() APIRegistry
ProtocolRegistry() protocols.ProtocolRegistry
ProtocolRegistry() ProtocolRegistry
Identity() ed25519.PrivateKey
Storage() StorageService
SetIdentity(identity ed25519.PrivateKey)

View File

@ -4,3 +4,9 @@ type Protocol interface {
Initialize(portal Portal) error
Start() error
}
type ProtocolRegistry interface {
Register(name string, protocol Protocol)
Get(name string) (Protocol, error)
All() map[string]Protocol
}

View File

@ -1,6 +1,8 @@
package protocols
func Init(registry ProtocolRegistry) error {
import "git.lumeweb.com/LumeWeb/portal/interfaces"
func Init(registry interfaces.ProtocolRegistry) error {
registry.Register("s5", NewS5Protocol())
return nil
}

View File

@ -6,20 +6,14 @@ import (
)
var (
_ ProtocolRegistry = (*ProtocolRegistryImpl)(nil)
_ interfaces.ProtocolRegistry = (*ProtocolRegistryImpl)(nil)
)
type ProtocolRegistry interface {
Register(name string, protocol interfaces.Protocol)
Get(name string) (interfaces.Protocol, error)
All() map[string]interfaces.Protocol
}
type ProtocolRegistryImpl struct {
protocols map[string]interfaces.Protocol
}
func NewProtocolRegistry() ProtocolRegistry {
func NewProtocolRegistry() interfaces.ProtocolRegistry {
return &ProtocolRegistryImpl{
protocols: make(map[string]interfaces.Protocol),
}