Export db datatypes,tools
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
)
|
||||
|
||||
type DataTyp uint16
|
||||
|
||||
const (
|
||||
DATA_ACCOUNT DataTyp = iota
|
||||
DATA_ACCOUNT_CREATED
|
||||
DATA_TRACKING_ID
|
||||
DATA_PUBLIC_KEY
|
||||
DATA_CUSTODIAL_ID
|
||||
DATA_ACCOUNT_PIN
|
||||
DATA_ACCOUNT_STATUS
|
||||
DATA_FIRST_NAME
|
||||
DATA_FAMILY_NAME
|
||||
DATA_YOB
|
||||
DATA_LOCATION
|
||||
DATA_GENDER
|
||||
DATA_OFFERINGS
|
||||
DATA_RECIPIENT
|
||||
DATA_AMOUNT
|
||||
DATA_TEMPORARY_PIN
|
||||
DATA_VOUCHER_LIST
|
||||
DATA_TEMPORARY_SYM
|
||||
DATA_ACTIVE_SYM
|
||||
DATA_TEMPORARY_BAL
|
||||
DATA_ACTIVE_BAL
|
||||
DATA_PUBLIC_KEY_REVERSE
|
||||
)
|
||||
|
||||
func typToBytes(typ DataTyp) []byte {
|
||||
var b [2]byte
|
||||
binary.BigEndian.PutUint16(b[:], uint16(typ))
|
||||
return b[:]
|
||||
}
|
||||
|
||||
func PackKey(typ DataTyp, data []byte) []byte {
|
||||
v := typToBytes(typ)
|
||||
return append(v, data...)
|
||||
}
|
||||
@@ -3,13 +3,15 @@ package utils
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.grassecon.net/urdt/ussd/common"
|
||||
|
||||
"git.defalsify.org/vise.git/db"
|
||||
)
|
||||
|
||||
type DataStore interface {
|
||||
db.Db
|
||||
ReadEntry(ctx context.Context, sessionId string, typ DataTyp) ([]byte, error)
|
||||
WriteEntry(ctx context.Context, sessionId string, typ DataTyp, value []byte) error
|
||||
ReadEntry(ctx context.Context, sessionId string, typ common.DataTyp) ([]byte, error)
|
||||
WriteEntry(ctx context.Context, sessionId string, typ common.DataTyp, value []byte) error
|
||||
}
|
||||
|
||||
type UserDataStore struct {
|
||||
@@ -17,16 +19,16 @@ type UserDataStore struct {
|
||||
}
|
||||
|
||||
// ReadEntry retrieves an entry from the store based on the provided parameters.
|
||||
func (store *UserDataStore) ReadEntry(ctx context.Context, sessionId string, typ DataTyp) ([]byte, error) {
|
||||
func (store *UserDataStore) ReadEntry(ctx context.Context, sessionId string, typ common.DataTyp) ([]byte, error) {
|
||||
store.SetPrefix(db.DATATYPE_USERDATA)
|
||||
store.SetSession(sessionId)
|
||||
k := PackKey(typ, []byte(sessionId))
|
||||
k := common.PackKey(typ, []byte(sessionId))
|
||||
return store.Get(ctx, k)
|
||||
}
|
||||
|
||||
func (store *UserDataStore) WriteEntry(ctx context.Context, sessionId string, typ DataTyp, value []byte) error {
|
||||
func (store *UserDataStore) WriteEntry(ctx context.Context, sessionId string, typ common.DataTyp, value []byte) error {
|
||||
store.SetPrefix(db.DATATYPE_USERDATA)
|
||||
store.SetSession(sessionId)
|
||||
k := PackKey(typ, []byte(sessionId))
|
||||
k := common.PackKey(typ, []byte(sessionId))
|
||||
return store.Put(ctx, k, value)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user