Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
feat: use env var for conf
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Feb 21, 2023
1 parent 5f98458 commit b1f91c3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
8 changes: 2 additions & 6 deletions blockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ var errNotImplemented = errors.New("not implemented")

const GetBlockTimeout = time.Second * 60

func newExchange(orchestrator, loggingEndpoint string) (exchange.Interface, error) {
b, err := newCabooseBlockStore(orchestrator, loggingEndpoint)
if err != nil {
return nil, err
}
return &exchangeBsWrapper{bstore: b}, nil
func newExchange(bs blockstore.Blockstore) (exchange.Interface, error) {
return &exchangeBsWrapper{bstore: bs}, nil
}

type exchangeBsWrapper struct {
Expand Down
7 changes: 4 additions & 3 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/filecoin-saturn/caboose"
"github.com/ipfs/go-blockservice"
blockstore "github.com/ipfs/go-ipfs-blockstore"
bstore "github.com/ipfs/go-ipfs-blockstore"
"github.com/ipfs/go-libipfs/gateway"
"github.com/ipfs/interface-go-ipfs-core/path"
Expand Down Expand Up @@ -39,9 +40,9 @@ func withRequestLogger(next http.Handler) http.Handler {
})
}

func makeGatewayHandler(saturnOrchestrator, saturnLogger string, kuboRPC []string, port int, blockCacheSize int) (*http.Server, error) {
// Sets up an exchange based on using Saturn as block storage
exch, err := newExchange(saturnOrchestrator, saturnLogger)
func makeGatewayHandler(bs blockstore.Blockstore, kuboRPC []string, port int, blockCacheSize int) (*http.Server, error) {
// Sets up an exchange based on the given Block Store
exch, err := newExchange(bs)
if err != nil {
return nil, err
}
Expand Down
14 changes: 13 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"
"sync"

blockstore "github.com/ipfs/go-ipfs-blockstore"
golog "github.com/ipfs/go-log/v2"
"github.com/spf13/cobra"
)
Expand All @@ -31,6 +32,7 @@ const (

EnvSaturnLogger = "STRN_LOGGER_URL"
EnvSaturnOrchestrator = "STRN_ORCHESTRATOR_URL"
EnvProxyBlockStore = "PROXY_BLOCKSTORE"
EnvBlockCacheSize = "BLOCK_CACHE_SIZE"
EnvKuboRPC = "KUBO_RPC_URLS"
)
Expand Down Expand Up @@ -65,7 +67,17 @@ var rootCmd = &cobra.Command{

log.Printf("Starting %s %s", name, version)

gatewaySrv, err := makeGatewayHandler(saturnOrchestrator, saturnLogger, kuboRPC, gatewayPort, blockCacheSize)
var bs blockstore.Blockstore
if proxy := os.Getenv(EnvProxyBlockStore); proxy != "" {
bs = newProxyBlockStore(proxy, nil)
} else {
bs, err = newCabooseBlockStore(saturnOrchestrator, saturnLogger)
if err != nil {
return err
}
}

gatewaySrv, err := makeGatewayHandler(bs, kuboRPC, gatewayPort, blockCacheSize)
if err != nil {
return err
}
Expand Down

0 comments on commit b1f91c3

Please sign in to comment.