Moved coords in separate module.

This commit is contained in:
Sascha L. Teichmann 2014-08-16 16:06:42 +02:00
parent 120531ed78
commit b6c041b896
2 changed files with 6 additions and 4 deletions

View File

@ -2,11 +2,11 @@
// Use of this source code is governed by the MIT license // Use of this source code is governed by the MIT license
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
package main package common
import "strconv" import "strconv"
// Constructs a database key out of byte slice. // 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) return strconv.ParseInt(string(key), 10, 64)
} }

View File

@ -10,6 +10,8 @@ import (
"sync" "sync"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"bitbucket.org/s_l_teichmann/mtredisalize/common"
) )
var globalLock sync.RWMutex 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) { func (ss *SqliteSession) Fetch(hash, key []byte) (data []byte, err error) {
var pos int64 var pos int64
if pos, err = bytes2pos(key); err != nil { if pos, err = common.DecodePosFromBytes(key); err != nil {
return return
} }
@ -159,7 +161,7 @@ func (ss *SqliteSession) InTransaction() bool {
func (ss *SqliteSession) Store(hash, key, value []byte) (exists bool, err error) { func (ss *SqliteSession) Store(hash, key, value []byte) (exists bool, err error) {
var pos int64 var pos int64
if pos, err = bytes2pos(key); err != nil { if pos, err = common.DecodePosFromBytes(key); err != nil {
return return
} }