fix: need to create init for storage service to ensure it configures the http client after we have read the config

This commit is contained in:
Derrick Hammer 2024-01-15 08:38:05 -05:00
parent 592b20c561
commit ba44b58897
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 16 additions and 6 deletions

View File

@ -125,6 +125,11 @@ func (p *PortalImpl) getInitFuncs() []func() error {
func() error {
return protocols.Init(p.protocolRegistry)
},
func() error {
p.storage.Init()
return nil
},
func() error {
return api.Init(p.apiRegistry)
},

View File

@ -3,5 +3,6 @@ package interfaces
import "io"
type StorageService interface {
Init()
PutFile(file io.ReadSeeker, bucket string, generateProof bool) ([]byte, error)
}

View File

@ -19,14 +19,9 @@ type StorageServiceImpl struct {
}
func NewStorageService(portal interfaces.Portal) interfaces.StorageService {
client := resty.New()
client.SetBaseURL(portal.Config().GetString("core.sia.url"))
client.SetBasicAuth("", portal.Config().GetString("core.sia.key"))
return &StorageServiceImpl{
portal: portal,
httpApi: client,
httpApi: nil,
}
}
@ -62,3 +57,12 @@ func (s StorageServiceImpl) PutFile(file io.ReadSeeker, bucket string, generateP
return hash[:], nil
}
func (s *StorageServiceImpl) Init() {
client := resty.New()
client.SetBaseURL(s.portal.Config().GetString("core.sia.url"))
client.SetBasicAuth("", s.portal.Config().GetString("core.sia.key"))
s.httpApi = client
}