Skip to content

Commit 91c7053

Browse files
committed
Rename importers into data sources for clarity.
1 parent 855f1f4 commit 91c7053

File tree

18 files changed

+97
-92
lines changed

18 files changed

+97
-92
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# Release artifacts
2020
*.tar.gz
2121
go-graphkb
22-
importer-csv
22+
datasource-csv
2323

2424
.config.yml
2525
main

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ script:
99
- .travis/run.sh
1010

1111
before_deploy:
12-
- tar cvf graphkb-$TRAVIS_TAG.tar.gz web/build go-graphkb importer-csv
12+
- tar cvf graphkb-$TRAVIS_TAG.tar.gz web/build go-graphkb datasource-csv
1313
- echo Deploying GraphKB $TRAVIS_TAG to GitHub Releases
1414
deploy:
1515
provider: releases

.travis/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ docker build -t go-graphkb-build .
44

55
cid=`docker create go-graphkb-build`
66
docker cp $cid:/node/src/go-graphkb .
7-
docker cp $cid:/node/src/importer-csv .
7+
docker cp $cid:/node/src/datasource-csv .
88
docker cp $cid:/node/src/build web/
99
docker rm $cid

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ COPY cmd cmd
99
COPY graphkb graphkb
1010
COPY internal internal
1111
RUN cd cmd/go-graphkb && GOOS=linux GOARCH=amd64 go build -o go-graphkb main.go
12-
RUN cd cmd/go-graphkb && GOOS=linux GOARCH=amd64 go build -o importer-csv main.go
12+
RUN cd cmd/go-graphkb && GOOS=linux GOARCH=amd64 go build -o datasource-csv main.go
1313

1414

1515

@@ -22,4 +22,4 @@ COPY web .
2222
RUN yarn install && yarn build
2323

2424
COPY --from=go-builder /go/src/cmd/go-graphkb/go-graphkb ./
25-
COPY --from=go-builder /go/src/cmd/go-graphkb/importer-csv ./
25+
COPY --from=go-builder /go/src/cmd/go-graphkb/datasource-csv ./

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Run the following commands
1717

1818
# Insert the example data available in examples/ directory
1919
# with the following command:
20-
go run cmd/importer-csv/main.go --config cmd/importer-csv/config.yml
20+
go run cmd/datasource-csv/main.go --config cmd/datasource-csv/config.yml
2121

2222
Then visit the web UI accessible at http://127.0.0.1:3000.
2323

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
graphkb_url: "http://localhost:8080"
2-
graphkb_auth_token: "importer-csv"
2+
graphkb_auth_token: "datasource-csv"
33
graphkb_skip_verify: true
44

55
path: "example.csv"

cmd/importer-csv/example.csv renamed to cmd/datasource-csv/example.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
source_type,source_value,relation_type,destination_type,destination_value
12
employee,James,work_at,office,New York
23
employee,Paul,work_at,office,Paris
34
employee,Jean,work_at,office,Paris

cmd/importer-csv/main.go renamed to cmd/datasource-csv/main.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ import (
1212
"github.com/spf13/viper"
1313
)
1414

15+
// CSVSource represent a CSV source file
1516
type CSVSource struct {
1617
dataPath string
1718
}
1819

20+
// NewCSVSource create a new instance of CSV source
1921
func NewCSVSource() *CSVSource {
2022
csvSource := new(CSVSource)
2123
csvSource.dataPath = viper.GetString("path")
@@ -27,7 +29,8 @@ func NewCSVSource() *CSVSource {
2729
return csvSource
2830
}
2931

30-
func (cs *CSVSource) Start(importer *graphkb.GraphImporter) error {
32+
// Start the CSVSource fetching
33+
func (cs *CSVSource) Start(dataSource *graphkb.DataSource) error {
3134
file, err := os.Open(cs.dataPath)
3235
if err != nil {
3336
return err
@@ -36,12 +39,12 @@ func (cs *CSVSource) Start(importer *graphkb.GraphImporter) error {
3639

3740
r := csv.NewReader(file)
3841

39-
previousGraph, err := importer.ReadCurrentGraph()
42+
previousGraph, err := dataSource.ReadCurrentGraph()
4043
if err != nil {
4144
return fmt.Errorf("Unable to read previous graph: %v", err)
4245
}
4346

44-
tx := importer.CreateTransaction(previousGraph)
47+
tx := dataSource.CreateTransaction(previousGraph)
4548

4649
header := true
4750

@@ -74,6 +77,7 @@ func (cs *CSVSource) Start(importer *graphkb.GraphImporter) error {
7477
return err
7578
}
7679

80+
// Stop the CSV source
7781
func (cs *CSVSource) Stop() error {
7882
return nil
7983
}
@@ -99,7 +103,7 @@ func main() {
99103
Use: "source-csv [opts]",
100104
Run: func(cmd *cobra.Command, args []string) {
101105

102-
options := graphkb.ImporterOptions{
106+
options := graphkb.DataSourceOptions{
103107
URL: viper.GetString("graphkb_url"),
104108
AuthToken: viper.GetString("graphkb_auth_token"),
105109
SkipVerify: viper.GetBool("graphkb_skip_verify"),

graphkb/importer.go renamed to graphkb/data_source.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ package graphkb
33
import (
44
"fmt"
55

6-
"github.com/clems4ever/go-graphkb/internal/importers"
76
"github.com/clems4ever/go-graphkb/internal/knowledge"
87
"github.com/clems4ever/go-graphkb/internal/schema"
8+
"github.com/clems4ever/go-graphkb/internal/sources"
99
)
1010

11-
// ImporterOptions options for configuring importer
12-
type ImporterOptions struct {
11+
// DataSourceOptions options for configuring the data source
12+
type DataSourceOptions struct {
1313
URL string
1414
AuthToken string
1515
SkipVerify bool
1616
}
1717

18-
// Start the importer with provided options
19-
func Start(source importers.Importer, options ImporterOptions) error {
18+
// Start the data source with provided options
19+
func Start(source sources.DataSource, options DataSourceOptions) error {
2020
if options.URL == "" {
2121
return fmt.Errorf("Please provide graphkb URL in configuration file")
2222
}
@@ -25,10 +25,10 @@ func Start(source importers.Importer, options ImporterOptions) error {
2525
}
2626

2727
api := knowledge.NewGraphAPI(options.URL, options.AuthToken, options.SkipVerify)
28-
graphImporter := knowledge.NewGraphImporter(api)
28+
dataSourceAPI := knowledge.NewDataSource(api)
2929

30-
if err := source.Start(graphImporter); err != nil {
31-
return fmt.Errorf("Unable to start importer: %v", err)
30+
if err := source.Start(dataSourceAPI); err != nil {
31+
return fmt.Errorf("Unable to start data source: %v", err)
3232
}
3333

3434
return nil

graphkb/graph_importer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ package graphkb
22

33
import "github.com/clems4ever/go-graphkb/internal/knowledge"
44

5-
type GraphImporter = knowledge.GraphImporter
5+
type DataSource = knowledge.DataSource
66

77
type Transaction = knowledge.Transaction

0 commit comments

Comments
 (0)