Skip to content

Commit 54a9560

Browse files
committed
Add builder for data store backends
1 parent 310a7eb commit 54a9560

3 files changed

Lines changed: 20 additions & 9 deletions

File tree

connections/data_source.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package connections
22

33
import (
44
"context"
5-
"fmt"
65
ds "github.com/Zondax/zindexer/connections/data_store"
76
"github.com/coinbase/rosetta-sdk-go/client"
87
"gorm.io/gorm"
@@ -70,13 +69,10 @@ func WithNodeClient(node interface{}) SourceOption {
7069

7170
func WithDataStore(cfg ds.DataStoreConfig) SourceOption {
7271
return func(w *DataSource) {
73-
switch cfg.Service {
74-
case ds.MinIOStorage:
75-
c, _ := ds.NewMinioClient(cfg)
76-
w.DataStore = ds.DataStoreClient{Client: c}
77-
return
78-
default:
79-
panic(fmt.Errorf("DataStore with service %s, is not available", cfg.Service))
72+
client, err := ds.NewDataStoreClient(cfg)
73+
if err != nil {
74+
panic(err)
8075
}
76+
w.DataStore = client
8177
}
8278
}

connections/data_store/builder.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package data_store
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
func NewDataStoreClient(config DataStoreConfig) (DataStoreClient, error) {
8+
switch config.Service {
9+
case MinIOStorage:
10+
client, err := newMinioClient(config)
11+
return DataStoreClient{client}, err
12+
default:
13+
return DataStoreClient{}, fmt.Errorf("unrecognized data store service '%s'", config.Service)
14+
}
15+
}

connections/data_store/minio.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type MinioClient struct {
1515
client *minio.Client
1616
}
1717

18-
func NewMinioClient(config DataStoreConfig) (MinioClient, error) {
18+
func newMinioClient(config DataStoreConfig) (MinioClient, error) {
1919
minioClient, err := minio.New(config.Url, &minio.Options{
2020
Creds: credentials.NewStaticV4(config.User, config.Password, ""),
2121
Secure: true,

0 commit comments

Comments
 (0)