@@ -12,10 +12,12 @@ import (
12
12
"github.com/spf13/viper"
13
13
)
14
14
15
+ // CSVSource represent a CSV source file
15
16
type CSVSource struct {
16
17
dataPath string
17
18
}
18
19
20
+ // NewCSVSource create a new instance of CSV source
19
21
func NewCSVSource () * CSVSource {
20
22
csvSource := new (CSVSource )
21
23
csvSource .dataPath = viper .GetString ("path" )
@@ -27,7 +29,8 @@ func NewCSVSource() *CSVSource {
27
29
return csvSource
28
30
}
29
31
30
- func (cs * CSVSource ) Start (importer * graphkb.GraphImporter ) error {
32
+ // Start the CSVSource fetching
33
+ func (cs * CSVSource ) Start (dataSource * graphkb.DataSource ) error {
31
34
file , err := os .Open (cs .dataPath )
32
35
if err != nil {
33
36
return err
@@ -36,12 +39,12 @@ func (cs *CSVSource) Start(importer *graphkb.GraphImporter) error {
36
39
37
40
r := csv .NewReader (file )
38
41
39
- previousGraph , err := importer .ReadCurrentGraph ()
42
+ previousGraph , err := dataSource .ReadCurrentGraph ()
40
43
if err != nil {
41
44
return fmt .Errorf ("Unable to read previous graph: %v" , err )
42
45
}
43
46
44
- tx := importer .CreateTransaction (previousGraph )
47
+ tx := dataSource .CreateTransaction (previousGraph )
45
48
46
49
header := true
47
50
@@ -74,6 +77,7 @@ func (cs *CSVSource) Start(importer *graphkb.GraphImporter) error {
74
77
return err
75
78
}
76
79
80
+ // Stop the CSV source
77
81
func (cs * CSVSource ) Stop () error {
78
82
return nil
79
83
}
@@ -99,7 +103,7 @@ func main() {
99
103
Use : "source-csv [opts]" ,
100
104
Run : func (cmd * cobra.Command , args []string ) {
101
105
102
- options := graphkb.ImporterOptions {
106
+ options := graphkb.DataSourceOptions {
103
107
URL : viper .GetString ("graphkb_url" ),
104
108
AuthToken : viper .GetString ("graphkb_auth_token" ),
105
109
SkipVerify : viper .GetBool ("graphkb_skip_verify" ),
0 commit comments