mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
add state key as the prefix
This commit is contained in:
parent
17928986b8
commit
f3691489dd
|
@ -134,7 +134,7 @@ func loadPersistenceFields(obj interface{}, id string, persistence service.Persi
|
||||||
return iterateFieldsByTag(obj, "persistence", func(tag string, field reflect.StructField, value reflect.Value) error {
|
return iterateFieldsByTag(obj, "persistence", func(tag string, field reflect.StructField, value reflect.Value) error {
|
||||||
newValueInf := newTypeValueInterface(value.Type())
|
newValueInf := newTypeValueInterface(value.Type())
|
||||||
// inf := value.Interface()
|
// inf := value.Interface()
|
||||||
store := persistence.NewStore(id, tag)
|
store := persistence.NewStore("state", id, tag)
|
||||||
if err := store.Load(&newValueInf); err != nil {
|
if err := store.Load(&newValueInf); err != nil {
|
||||||
if err == service.ErrPersistenceNotExists {
|
if err == service.ErrPersistenceNotExists {
|
||||||
return nil
|
return nil
|
||||||
|
@ -159,7 +159,7 @@ func storePersistenceFields(obj interface{}, id string, persistence service.Pers
|
||||||
return iterateFieldsByTag(obj, "persistence", func(tag string, ft reflect.StructField, fv reflect.Value) error {
|
return iterateFieldsByTag(obj, "persistence", func(tag string, ft reflect.StructField, fv reflect.Value) error {
|
||||||
inf := fv.Interface()
|
inf := fv.Interface()
|
||||||
|
|
||||||
store := persistence.NewStore(id, tag)
|
store := persistence.NewStore("state", id, tag)
|
||||||
return store.Save(inf)
|
return store.Save(inf)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,13 +70,13 @@ func Test_storePersistenceFields(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
var i int64
|
var i int64
|
||||||
store := ps.NewStore("test-struct", "integer")
|
store := ps.NewStore("state", "test-struct", "integer")
|
||||||
err = store.Load(&i)
|
err = store.Load(&i)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, int64(1), i)
|
assert.Equal(t, int64(1), i)
|
||||||
|
|
||||||
var p *types.Position
|
var p *types.Position
|
||||||
store = ps.NewStore("test-struct", "position")
|
store = ps.NewStore("state", "test-struct", "position")
|
||||||
err = store.Load(&p)
|
err = store.Load(&p)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, fixedpoint.NewFromFloat(10.0), p.Base)
|
assert.Equal(t, fixedpoint.NewFromFloat(10.0), p.Base)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -38,7 +37,6 @@ func (store *MemoryStore) Load(val interface{}) error {
|
||||||
v := reflect.ValueOf(val)
|
v := reflect.ValueOf(val)
|
||||||
if data, ok := store.memory.Slots[store.Key]; ok {
|
if data, ok := store.memory.Slots[store.Key]; ok {
|
||||||
dataRV := reflect.ValueOf(data)
|
dataRV := reflect.ValueOf(data)
|
||||||
fmt.Printf("load %s = %v\n", store.Key, dataRV)
|
|
||||||
v.Elem().Set(dataRV)
|
v.Elem().Set(dataRV)
|
||||||
} else {
|
} else {
|
||||||
return ErrPersistenceNotExists
|
return ErrPersistenceNotExists
|
||||||
|
|
|
@ -21,7 +21,7 @@ func TestMemoryService(t *testing.T) {
|
||||||
store := service.NewStore("test")
|
store := service.NewStore("test")
|
||||||
|
|
||||||
i := 3
|
i := 3
|
||||||
err := store.Save(&i)
|
err := store.Save(i)
|
||||||
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user