From b6c041b896968774b1a0b9ec1c57b0f6fb0e9bd0 Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Sat, 16 Aug 2014 16:06:42 +0200 Subject: [PATCH] Moved coords in separate module. --- coords.go => common/coords.go | 4 ++-- sqlite.go | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) rename coords.go => common/coords.go (77%) 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 }