forked from application-research/estuary
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove function pointers from Config struct
- Loading branch information
1 parent
3906546
commit f03eef4
Showing
6 changed files
with
95 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/application-research/estuary/config" | ||
"github.com/ipfs/go-cid" | ||
blockstore "github.com/ipfs/go-ipfs-blockstore" | ||
) | ||
|
||
type Initializer struct { | ||
cfg *config.Config | ||
} | ||
|
||
func (init Initializer) Config() *config.Config { | ||
return init.cfg | ||
} | ||
|
||
func (init Initializer) BlockstoreWrap(blk blockstore.Blockstore) (blockstore.Blockstore, error) { | ||
return blk, nil | ||
} | ||
|
||
func (init Initializer) KeyProviderFunc(context.Context) (<-chan cid.Cid, error) { | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/application-research/estuary/config" | ||
"github.com/ipfs/go-cid" | ||
blockstore "github.com/ipfs/go-ipfs-blockstore" | ||
"gorm.io/gorm" | ||
) | ||
|
||
type Initializer struct { | ||
cfg *config.Config | ||
db *gorm.DB | ||
trackingBstore *TrackingBlockstore | ||
} | ||
|
||
func (init Initializer) Config() *config.Config { | ||
return init.cfg | ||
} | ||
|
||
func (init Initializer) BlockstoreWrap(bs blockstore.Blockstore) (blockstore.Blockstore, error) { | ||
init.trackingBstore = NewTrackingBlockstore(bs, init.db) | ||
return init.trackingBstore, nil | ||
} | ||
|
||
func (init Initializer) KeyProviderFunc(rpctx context.Context) (<-chan cid.Cid, error) { | ||
log.Infof("running key provider func") | ||
out := make(chan cid.Cid) | ||
go func() { | ||
defer close(out) | ||
|
||
var contents []Content | ||
if err := init.db.Find(&contents, "active").Error; err != nil { | ||
log.Errorf("failed to load contents for reproviding: %s", err) | ||
return | ||
} | ||
log.Infof("key provider func returning %d values", len(contents)) | ||
|
||
for _, c := range contents { | ||
select { | ||
case out <- c.Cid.CID: | ||
case <-rpctx.Done(): | ||
return | ||
} | ||
} | ||
}() | ||
return out, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters