diff options
author | Matthew Lemon <matt@matthewlemon.com> | 2020-07-26 20:00:30 +0100 |
---|---|---|
committer | Matthew Lemon <matt@matthewlemon.com> | 2020-07-26 20:00:30 +0100 |
commit | 3638135ee62347ca267eaf0d6c83703accd36f8e (patch) | |
tree | 677c655c7a4aece7f0dd0f9e35a4aedbe3628543 /pkg | |
parent | 3d9fcd0c1d56a5f5534163d56c9d65321ded4bc5 (diff) |
added re-typed []DatamapLine
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/datamaps/config.go | 12 | ||||
-rw-r--r-- | pkg/datamaps/db.go | 2 | ||||
-rw-r--r-- | pkg/datamaps/reader.go | 19 |
3 files changed, 18 insertions, 15 deletions
diff --git a/pkg/datamaps/config.go b/pkg/datamaps/config.go index 84e097b..7c7f8e7 100644 --- a/pkg/datamaps/config.go +++ b/pkg/datamaps/config.go @@ -14,7 +14,7 @@ const ( // mocking funcs in go https://stackoverflow.com/questions/19167970/mock-functions-in-go // we only need the func signature to create the type. This is pretty weird, we're want to mock // os.UserHomeDir so that we can set it to something like /tmp in our tests. Here we are creating -// two types: GetUserConfigDir to represent the os.UserConfigDir function, DBPathChecker as a wrapper +// two types: GetUserConfigDir to represent the os.UserConfigDir function, dbPathChecker as a wrapper // which which we can assign methods to that holds the value of the func os.UserConfigDir and the // method, check(), which does the work, using the passed in func to determine the user $HOME/.config // directory. @@ -25,21 +25,21 @@ const ( // for testing purposes. type GetUserConfigDir func() (string, error) -// DBPathChecker contains the func used to create the user config dir. -type DBPathChecker struct { +// dbPathChecker contains the func used to create the user config dir. +type dbPathChecker struct { getUserConfigDir GetUserConfigDir } // NewDBPathChecker creaes a DBPathChecker using whatever // func you want as the argument, as long as it produces // the user config directory. -func NewDBPathChecker(h GetUserConfigDir) *DBPathChecker { - return &DBPathChecker{getUserConfigDir: h} +func NewDBPathChecker(h GetUserConfigDir) *dbPathChecker { + return &dbPathChecker{getUserConfigDir: h} } // Check returns true if the necessary config files (including // the database) are in place - false if not -func (db *DBPathChecker) Check() bool { +func (db *dbPathChecker) Check() bool { userConfig, err := db.getUserConfigDir() if err != nil { log.Fatal(err) diff --git a/pkg/datamaps/db.go b/pkg/datamaps/db.go index 9f9d669..9ae2204 100644 --- a/pkg/datamaps/db.go +++ b/pkg/datamaps/db.go @@ -53,7 +53,7 @@ func SetupDB(path string) (*sql.DB, error) { } // DatamapToDB takes a slice of DatamapLine and writes it to a sqlite3 db file. -// func DatafmapToDB(d_path string, data []DatamapLine, dm_name string, dm_path string) error { +// func DatafmapToDB(d_path string, data ExtractedDatamapFile, dm_name string, dm_path string) error { func DatamapToDB(opts *Options) error { fmt.Printf("Importing datamap file %s and naming it %s.\n", opts.DMPath, opts.DMName) diff --git a/pkg/datamaps/reader.go b/pkg/datamaps/reader.go index 892e4d8..a754fa1 100644 --- a/pkg/datamaps/reader.go +++ b/pkg/datamaps/reader.go @@ -45,6 +45,8 @@ type ExtractedCell struct { Value string } +type ExtractedDatamapFile []DatamapLine + //sheetInSlice is a helper which returns true // if a string is in a slice of strings. func sheetInSlice(list []string, key string) bool { @@ -59,7 +61,7 @@ func sheetInSlice(list []string, key string) bool { //getSheetNames returns the number of Sheet field entries // in a slice of DatamapLine structs. -func getSheetNames(dmls []DatamapLine) []string { +func getSheetNames(dmls ExtractedDatamapFile) []string { var sheetNames []string for _, dml := range dmls { @@ -71,9 +73,10 @@ func getSheetNames(dmls []DatamapLine) []string { return sheetNames } -//ReadDML returns a slice of DatamapLine structs. -func ReadDML(path string) ([]DatamapLine, error) { - var s []DatamapLine +// ReadDML returns a slice of DatamapLine structs given a +// path to a datamap file. +func ReadDML(path string) (ExtractedDatamapFile, error) { + var s ExtractedDatamapFile data, err := ioutil.ReadFile(path) @@ -147,11 +150,11 @@ func ReadXLSX(ssheet string) FileData { return outer } -// DatamapFromDB fetches a slice of DatamapLine from the database given +// DatamapFromDB fetches an ExtractedDatamapFile from the database given // the name of a datamap. -func DatamapFromDB(name string, db *sql.DB) ([]DatamapLine, error) { +func DatamapFromDB(name string, db *sql.DB) (ExtractedDatamapFile, error) { - var out []DatamapLine + var out ExtractedDatamapFile query := ` select @@ -185,7 +188,7 @@ func DatamapFromDB(name string, db *sql.DB) ([]DatamapLine, error) { // from the populated spreadsheet file file. func ExtractDBDM(name string, file string, db *sql.DB) (ExtractedData, error) { xdata := ReadXLSX(file) - ddata, err := DatamapFromDB(name, db) // this will need to return a []DatamapLine + ddata, err := DatamapFromDB(name, db) // this will need to return an ExtractedDatamapFile if err != nil { return nil, err |