From 7ac3c67e63f07282198b10a733c14d31ddcf4d7f Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Sun, 24 Apr 2016 18:37:08 +0200 Subject: [PATCH] Made mtdbconverter pass golint by adding the missing comments. --- cmd/mtdbconverter/leveldb.go | 8 ++++++++ cmd/mtdbconverter/sqlite.go | 12 +++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cmd/mtdbconverter/leveldb.go b/cmd/mtdbconverter/leveldb.go index ac08369..4d58192 100644 --- a/cmd/mtdbconverter/leveldb.go +++ b/cmd/mtdbconverter/leveldb.go @@ -13,6 +13,7 @@ import ( ) type ( + // LevelDBBlockProducer is a helper to fetch blocks from a LevelDB. LevelDBBlockProducer struct { db *leveldb.DB opts *leveldb.Options @@ -22,6 +23,7 @@ type ( decoder common.KeyDecoder } + // LevelDBBlockConsumer is a helper to store blocks in a LevelDB. LevelDBBlockConsumer struct { db *leveldb.DB opts *leveldb.Options @@ -31,6 +33,7 @@ type ( } ) +// NewLevelDBBlockProducer returns a new helper to fetch blocks from a LevelDB. func NewLevelDBBlockProducer(path string, splitter common.KeySplitter, decoder common.KeyDecoder) (ldbp *LevelDBBlockProducer, err error) { @@ -65,6 +68,7 @@ func NewLevelDBBlockProducer(path string, return } +// Close closes a helper to fetch blocks from a LevelDB. func (ldbp *LevelDBBlockProducer) Close() error { if ldbp.iterator != nil { ldbp.iterator.Close() @@ -75,6 +79,7 @@ func (ldbp *LevelDBBlockProducer) Close() error { return nil } +// Next fetches the next block from a LevelDB. func (ldbp *LevelDBBlockProducer) Next(block *common.Block) (err error) { if ldbp.iterator == nil { err = common.ErrNoMoreBlocks @@ -98,6 +103,7 @@ func (ldbp *LevelDBBlockProducer) Next(block *common.Block) (err error) { return } +// NewLevelDBBlockConsumer returns a new helper to store blocks in a LevelDB. func NewLevelDBBlockConsumer( path string, joiner common.KeyJoiner, @@ -120,6 +126,7 @@ func NewLevelDBBlockConsumer( return } +// Close closes a helper to store blocks in a LevelDB. func (ldbc *LevelDBBlockConsumer) Close() error { ldbc.wo.Close() ldbc.db.Close() @@ -127,6 +134,7 @@ func (ldbc *LevelDBBlockConsumer) Close() error { return nil } +// Consume stores a block in LevelDB. func (ldbc *LevelDBBlockConsumer) Consume(block *common.Block) (err error) { var encodedKey []byte if encodedKey, err = ldbc.encoder(ldbc.joiner(block.Coord)); err != nil { diff --git a/cmd/mtdbconverter/sqlite.go b/cmd/mtdbconverter/sqlite.go index 1c12c94..58249e0 100644 --- a/cmd/mtdbconverter/sqlite.go +++ b/cmd/mtdbconverter/sqlite.go @@ -21,17 +21,20 @@ const ( selectSQL = "SELECT pos, data FROM blocks" ) +// ErrDatabaseNotExists indicates that the database does not exist. var ErrDatabaseNotExists = errors.New("Database does not exists.") -const blocksPerTx = 128 +const blocksPerTx = 128 // Number of blocks copied in a transaction. type ( + // SQLiteBlockProducer helps getting blocks from a SQLite database. SQLiteBlockProducer struct { db *sql.DB rows *sql.Rows splitter common.KeySplitter } + // SQLiteBlockConsumer helps storing blocks into a SQLite database. SQLiteBlockConsumer struct { db *sql.DB insertStmt *sql.Stmt @@ -46,6 +49,7 @@ func fileExists(path string) bool { return !os.IsNotExist(err) } +// NewSQLiteBlockConsumer returns a storage helper for SQLite databases. func NewSQLiteBlockConsumer( path string, joiner common.KeyJoiner) (sbc *SQLiteBlockConsumer, err error) { @@ -91,6 +95,7 @@ func NewSQLiteBlockConsumer( return } +// Close closes a SQLite storage helper. func (sbc *SQLiteBlockConsumer) Close() error { sbc.tx.Commit() sbc.insertStmt.Close() @@ -112,6 +117,7 @@ func (sbc *SQLiteBlockConsumer) getTx() (tx *sql.Tx, err error) { return } +// Consume stores a block in an SQLite database. func (sbc *SQLiteBlockConsumer) Consume(block *common.Block) (err error) { var tx *sql.Tx if tx, err = sbc.getTx(); err != nil { @@ -121,6 +127,8 @@ func (sbc *SQLiteBlockConsumer) Consume(block *common.Block) (err error) { return } +// NewSQLiteBlockProducer returns a new producer to fetch blocks from a +// SQLite database. func NewSQLiteBlockProducer( path string, splitter common.KeySplitter) (sbp *SQLiteBlockProducer, err error) { @@ -149,6 +157,7 @@ func NewSQLiteBlockProducer( return } +// Next fetches the next block from a SQLite database. func (sbp *SQLiteBlockProducer) Next(block *common.Block) (err error) { if sbp.rows == nil { err = common.ErrNoMoreBlocks @@ -167,6 +176,7 @@ func (sbp *SQLiteBlockProducer) Next(block *common.Block) (err error) { return } +// Close closes a block producer from a SQLite database. func (sbp *SQLiteBlockProducer) Close() error { if sbp.rows != nil { sbp.rows.Close()