diff --git a/coords.go b/common/coords.go similarity index 77% rename from coords.go rename to common/coords.go index a9120f1..8b33b33 100644 --- a/coords.go +++ b/common/coords.go @@ -2,11 +2,11 @@ // Use of this source code is governed by the MIT license // that can be found in the LICENSE file. -package main +package common import "strconv" // Constructs a database key out of byte slice. -func bytes2pos(key []byte) (pos int64, err error) { +func DecodePosFromBytes(key []byte) (pos int64, err error) { return strconv.ParseInt(string(key), 10, 64) } diff --git a/sqlite.go b/sqlite.go index 27f70c1..2984eb0 100644 --- a/sqlite.go +++ b/sqlite.go @@ -10,6 +10,8 @@ import ( "sync" _ "github.com/mattn/go-sqlite3" + + "bitbucket.org/s_l_teichmann/mtredisalize/common" ) var globalLock sync.RWMutex @@ -137,7 +139,7 @@ func (ss *SqliteSession) txStmt(stmt *sql.Stmt) *sql.Stmt { func (ss *SqliteSession) Fetch(hash, key []byte) (data []byte, err error) { var pos int64 - if pos, err = bytes2pos(key); err != nil { + if pos, err = common.DecodePosFromBytes(key); err != nil { return } @@ -159,7 +161,7 @@ func (ss *SqliteSession) InTransaction() bool { func (ss *SqliteSession) Store(hash, key, value []byte) (exists bool, err error) { var pos int64 - if pos, err = bytes2pos(key); err != nil { + if pos, err = common.DecodePosFromBytes(key); err != nil { return }